I have a Java Class that's calling an SQL procedure to perform some DB operations. Here's my Java method:
public static void buildContent(String id) throws Exception{
Connection conn = ExtractDB.getConnection();
CallableStatement cs = null;
log.debug("arguments for the procedure is= "+id);
try {
cs = conn.prepareCall("{call CMS.relix.build_rp_data(?)}");
cs.setString(1, id);
cs.execute();
if(cs!=null)
{
cs.close();
}
} catch (SQLException e) {
log.error("Exception while executing the procedure", e);
}
finally{
if(cs!=null)
{
cs.close();
}
}
}
After few processing, it prints below error in the log and gets hanged over there(I have to terminate the process manually in order to stop execution):
Ora Err Msg :-1000
Ora Err Code :ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded
ORA-06512: at "CMS.relix", line 1700
ORA-06512: at line 1
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208) ...
I have tried below solution:
After adding "throw" in the catch block, the process is not getting hanged now and it continues execution after printing same SQL error.
catch (SQLException e) {
log.error("Exception while executing the procedure", e);
throw e;
}
I want your help to understand below points:
- how adding "throw e" to the code, let the program continue even after error?
- how to handle this error/exception to stop the processing and exit the program if this situation is encountered.
You didn't close Connection, use try with resources block
and remove
finallyblock