【问题标题】:com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'com.microsoft.sqlserver.jdbc.SQLServerException:“@P0”附近的语法不正确
【发布时间】:2013-06-20 13:43:23
【问题描述】:

我有一个返回一个输出参数的 SQL Server 2008 过程,我正在从 java 中调用它。我的代码如下

存储过程代码是

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));

但是被感染了.execute();正在生成以下错误

com.microsoft.sqlserver.jdbc.SQLServerException:“@P0”附近的语法不正确

请指导我哪里有问题

【问题讨论】:

标签: java sql-server sql-server-2008 jdbc


【解决方案1】:

正如@GregHNZ 提供的this link 所建议的那样,SQL Server 需要在调用周围使用一组花括号。

您的代码中的行如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 2015-12-12
    • 2013-12-16
    相关资源
    最近更新 更多