Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'

I have an SQL server 2008 procedure which is returning one out parameter, i am giving call to it from java. My code is given below

Stored procedure code is

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

Java Calling Code is

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

but infected.execute(); is generating the following error

com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '@P0'

kindly guide me where is problem

like image 523
WiXXeY Avatar asked Jun 24 '13 06:06

WiXXeY


1 Answers

As suggested by this link offered up by @GregHNZ, SQL Server requires a set of curly braces around the call.

The line in your code would look like this:

infected = con.prepareCall("{ call countInfected(?) }");
like image 129
Donald.McLean Avatar answered Oct 06 '22 04:10

Donald.McLean