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(?) }");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With