2013-06-24 52 views
7

我有一個SQL Server 2008程序正在返回一個輸出參數,我正在從java調用它。下面com.microsoft.sqlserver.jdbc.SQLServerException:'@ P0'附近的語法不正確

存儲過程的代碼我的代碼被賦予是

Create PROCEDURE countInfected @infected int out 
AS 
Select @infected = COUNT(*) from userInfo 
where userID NOT IN (Select userID from deletedInfo); 

Java的長途區號

CallableStatement infected = null; 
infected = con.prepareCall("call countInfected(?)"); 
infected.registerOutParameter(1, java.sql.Types.INTEGER); 
infected.execute(); 
System.out.println("Infected"+ infected.getInt(1)); 

但infected.execute();正在生成以下錯誤

com.microsoft.sqlserver.jdbc.SQLServerException:附近有語法錯誤@ P0'

親切指導我在哪裏的問題

+0

哪行觸發錯誤? – GregHNZ

+0

infected.execute(); – WiXXeY

+0

這對你有什麼好處:https://groups.google.com/forum/#!msg/mybatis-user/DxLHOn8LZU0/dFRgaIL7Ez8J?基本上把括號括起來,就像這個「{call countInfected(?)}」(我的SQL Server被烤了,所以我不能檢查)。 – GregHNZ

回答

10

正如this link提供了建議通過@GregHNZ,SQL Server需要圍繞該調用的一組花括號。

在你的代碼行是這樣的:

infected = con.prepareCall("{ call countInfected(?) }");