com.microsoft.sqlserver.jdbc.SQLServerException:未为参数设置该值

时间:2014-12-05 05:08:31

标签: java sql-server stored-procedures jdbc mssql-jdbc

我有时只会遇到此异常,就像在100次通话中一样。我寻找解决方案,但无法弄清楚。存储过程需要一个输入。我使用的驱动程序是sqljdbc4版本4.0

CREATE PROCEDURE [dbo].[PROC_CATEGORY_LIST] @USERID INT

我将参数设置如下

    "EXEC PROC_CATEGORY_LIST ?"
    callableStatement.setInt(1, userId);
    resultSet = callableStatement.executeQuery();

我收到以下异常

The value is not set for the parameter number 2.
com.microsoft.sqlserver.jdbc.SQLServerException: The value is not set for the parameter number 2.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildParamTypeDefinitions(SQLServerPreparedStatement.java:260)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.buildPreparedStrings(SQLServerPreparedStatement.java:219)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doPrepExec(SQLServerPreparedStatement.java:612)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:400)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:180)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:155)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:285)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport$StatementProxy.invoke(AbstractQueryReport.java:233)
    at com.sun.proxy.$Proxy2.executeQuery(Unknown Source)

有没有人遇到过这样的问题。如果是,可能的解决办法是什么。

0 个答案:

没有答案