Feedback
Did this article resolve your question/issue?

   

Article

Application using CallableStatement.execute() method did not return any data

Information

 
TitleApplication using CallableStatement.execute() method did not return any data
URL Nameexecute-method-invoked-by-callablestatement-object-did-not-return-any-data-even-if-the-data-exists
Article Number000144537
EnvironmentProduct: Connect for JDBC SQL Server driver
Version: 5.1
OS: Linux 7.x , 64 bit
Database: SQL Server 2016
Application: All supported applications
Question/Problem Description
Application using CallableStatement.execute() method to invoke a stored procedure did not return any data even if the data was there in the database table.

Snippet of the application code was the following:
boolean res = callableStatement.execute();
    System.out.println("call execute to invoke stored procedure");

    if(res) {
        rs = callableStatement.getResultSet();
        System.out.println("Selecting first row from table...");    
        while(rs.next()) {
        System.out.println(rs.getInt(1));
        }   
         } else {
             System.out.println("No data returned");
         }
    }
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
The application code was not correct when calling CallableStatement.execute() method. 
 
 
Resolution
According to the JDBC Specification ( reference given below in "Notes" ), the proper code snippet when using execute() method from a CallableStatement Object is the following:

CallableStatement cstmt = conn.prepareCall(procCall);
boolean retval = cstmt.execute();
ResultSet rs;
int count;
do {
                 if (retval == false)
                 { count = cstmt.getUpdateCount();
                    if (count == -1) { // no more results break; }
                    else { // process update count}
                 }
                else { // ResultSet
                          rs = cstmt.getResultSet();
                          // process ResultSet
                        }
               retval = cstmt.getMoreResults();
}
while (true);
Workaround
Notes
References to other documentation:
JDBC™ 4.2 Specification, 13.3.3.3 Returning Unknown or Multiple Results
http://download.oracle.com/otn-pub/jcp/jdbc-4_2-mrel2-spec/jdbc4.2-fr-spec.pdf
Last Modified Date11/13/2017 11:23 PM
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.