10

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

1

1 Answer 1

14

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(?) }");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.