jdbc call a stored procedure to obtain multiple result sets July 26, 2017 21:20:22 Kenny-Liu Reads: 1486 Copyright: This article is a blogger original article, shall not be reproduced without the bloggers allowed. HTTPS: // blog.csdn.net/L2388399752/article/details/76165734 these days, a remodeling company erp, use a lot of stored procedures, but I found that when using jdbc to call a stored procedure can not receive more results set (select the stored procedure returns the Result), but also difficult to find domestic solutions, today afternoon spent the afternoon, and finally realized. Conn Connection = JdbcUtil.getConnection (); CallableStatement stmt = null ; // call the stored procedure sqlserver exec method stmt = conn.prepareCall ( "EXEC dbo.sp_Query_GetVehiceTimeOuts '01'" ); // JDBC is a generic syntax // stmt = conn.prepareCall ( "{call dbo.sp_Query_GetVehiceTimeOuts () ?}");// stmt.setString (. 1, "01"); Boolean hashResult = stmt.execute (); the while ( to true ) { // is determined whether the present cycle is a data set IF (hashResult) { System.out.println ( "as data set " ); the ResultSet RS = stmt.getResultSet (); // the Do ... ResultSet something with the while (rs.next ()) { System.out.println (rs.getString ( . 1 )); } } the else { the System .out.println ( "The data is not set" ); int updateCount = stmt.getUpdateCount (); IF (updateCount == -1 ) { / * if updateCount is -1, the last one stored procedure returns representatives data set out of the loop * / System.out.println ( "last" ); BREAK ; } // the Do something with Update COUNT ... } / * each time it is determined whether a data set for stmt.getMoreResults () for the next time through the loop represented true data set, false empty * / hashResult = stmt.getMoreResults (); System.out.println (hashResult); } general logic is first loop, and then determine whether to submit sql return a result set of data received, if the processing proceeds to the result set, if not, obtained by a method in getUpdateCount result, and determines whether the result getUpdateCount -1, -1 is the last one result set, out of the loop when the result is -1, the cycle or continue this code