我的JDBC插入/更新命令有什么问题

时间:2012-05-21 16:24:35

标签: sql sql-server jdbc jtds

这是一个简单的预订/预订表:key是anId for timeOfBooking和dateOfBooking。

但是,当我尝试这样做时:插入if-not-exists,更新if-exist,关于使用此代码链接到时间的标识符:

declare anId varchar[18];
declare aDate;
declare aTimeStamp;
set @anId =?;
set @aDate=?;
set @aTimeStamp=?;
if (exists (select * from Booking as t  where t.AnId = @anId ))
begin update Booking set Date = @aDate and Time = @aTimeStamp  where AnId= @anId end
else begin insert into Booking (AnId, Date, Time) values(@anId , @aDate, @aTimeStamp) end ; 

我最终得到了返回此错误的jdbc层:

'varchar' is not a recognized CURSOR option.

知道什么是错的吗?

1 个答案:

答案 0 :(得分:2)

你应该把@换成变量名

declare @anId varchar(18);
declare @aDate datetime;
declare @aTimeStamp datetime;