How to resolve an exception that occurred while searching for a CURSOR from a Callable Statement in Java?

I have a Db2 return procedure that returns a cursor for one of the tables.

This procedure is called from my java code and truth to retrieve the cursor as a result set and to have a SQLexception exception log,

com.ibm.db2.jcc.am.jo: [jcc][t4][10335][10366][4.7.85] Invalid operation: Connection is closed. ERRORCODE=-4470, SQLSTATE=08003 at com.ibm.db2.jcc.am.dd.a(dd.java:666) at com.ibm.db2.jcc.am.dd.a(dd.java:60) 

I searched for a solution for this exception and found this solution on the ibm website, which suggests changing the log configuration,

Increase log file size and number of primary and secondary log files. You can also change the num_log_span value.

Here is an example procedure

 CREATE OR REPLACE PROCEDURE ABC(c_dump OUT SYS_REFCURSOR) IS BEGIN open c_dump FOR select feild1,feild1,.... from RSPNSE_TABLE; END; 

The following is the Java code,

 public void callStoredProc(){ Connection dbConnection = null; CallableStatement callableStatement = null; ResultSet rs = null; String proc = "{call ABC(?)}"; try { dbConnection = connection; callableStatement = dbConnection.prepareCall(proc); callableStatement.registerOutParameter(1, DB2Types.CURSOR); // execute getDBUSERCursor store procedure callableStatement.executeUpdate(); // get cursor and cast it to ResultSet rs = (ResultSet) callableStatement.getObject(1); } catch (SQLException e) { e.printStackTrace(); System.out.println(e.getMessage()); } } 

Now this Java code breaks into this line callableStatement = dbConnection.prepareCall(proc);

Note: Although the exception log contains the text β€œConnection closed”, I want to mention that I successfully established a connection with normal database extraction using JDBC, it has no problems.

+5
source share
1 answer

A call failure during a program call indicates that you do not have an open connection. You will have to delve into SQLException and pinpoint why.

0
source

All Articles