Java JDBC calls SqlServer stored procedure result set is empty

1. Problems


Using java's jdbc to call the SqlSever stored procedure, the error is reported as follows:

The error is obviously that no result set is returned. The code for calling the stored procedure is as follows:

String sql = "exec  usp_HKY_LoadConfig '" + date + "'";
Statement ps = conn.createStatement();
ps.setQueryTimeout(queryTimeOut);
ResultSet rs = ps.executeQuery(sql);

while (rs.next()) {
              ...
}

Two, solve


The stored procedure uses a temporary table, and rs always has no return value. Why is this? Although the cause was not found directly, a solution was found. Add set nocount on and set nocount off at the beginning and end of the stored procedure

begin
    set nocount on
    
      ...
     set nocount off            
end

Added , the result was found perfectly

 

Guess you like

Origin blog.csdn.net/qq_35995514/article/details/128479416