我有一个Java类,它调用一个SQL过程来执行一些DB操作。下面是我的Java方法:
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();
}
}
} 经过很少的处理后,它会在日志中打印下面的错误并挂在那里(为了停止执行,我必须手动终止进程):
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) ...我尝试了以下解决方案:
在catch块中添加“抛出”后,进程现在不会挂起,它在打印相同的SQL错误后继续执行。
catch (SQLException e) {
log.error("Exception while executing the procedure", e);
throw e;
}我希望你能帮助我理解以下几点:
发布于 2019-07-11 07:48:29
您没有关闭连接,请使用“尝试与资源”块
log.debug("arguments for the procedure is= "+id);
try (Connection conn = ExtractDB.getConnection();
CallableStatement cs = conn.prepareCall("{call CMS.relix.build_rp_data(?)}")) {并删除finally块
https://stackoverflow.com/questions/56984047
复制相似问题