我有一个Java类,它正在调用SQL过程来执行一些数据库操作。 这是我的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块中添加“ throw ”后,该进程现在未挂起,并且在打印相同的SQL错误后继续执行。
catch (SQLException e) {
log.error("Exception while executing the procedure", e);
throw e;
}
我希望您的帮助了解以下几点:
答案 0 :(得分:2)
您没有关闭连接,请对资源块使用try
log.debug("arguments for the procedure is= "+id);
try (Connection conn = ExtractDB.getConnection();
CallableStatement cs = conn.prepareCall("{call CMS.relix.build_rp_data(?)}")) {
并删除finally
块