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
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(?) }");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.