(转)jdbc 调用 sql server 的存储过程时“该语句没有返回结果集”的解决方法

时间:2021-05-31 18:32:43

本文转载自:http://hedyn.iteye.com/blog/856040

在JDBC中调用SQL Server中的存储过程时出现如下异常:

 

    com.microsoft.sqlserver.jdbc.SQLServerException: 该语句没有返回结果集。  
            at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)  
            at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:394)  
            at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)  
            at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)  
            at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)  
            at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)  
            at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)  
            at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)  

解决方法:在存储过程首行加上

SET NOCOUNT ON