第一次调用prepareStatement可以正常工作,但第二次得到java.sql.SQLException:连接已经关闭
我需要处理两个记录,为此,我最近安装了Oracle 11g数据库,并使用该数据库连接我的应用程序,每次检查记录是否存在时,我都会使用while循环运行批处理作业来处理这些记录,如果退出循环继续,则会继续。当我运行批处理作业时,首先使用第一次调用prepareStatement可以正常工作,但第二次得到java.sql.SQLException:连接已经关闭,java,oracle11g,weblogic,Java,Oracle11g,Weblogic,我需要处理两个记录,为此,我最近安装了Oracle 11g数据库,并使用该数据库连接我的应用程序,每次检查记录是否存在时,我都会使用while循环运行批处理作业来处理这些记录,如果退出循环继续,则会继续。当我运行批处理作业时,首先使用m_dbConnection.prepareStatement(查询)获取记录第一次它将获取记录并完成处理,第二次它将检查我们称为同一语句的记录m_dbConnection.prepareStatement(query)当我第二次调用时,我得到了java.sql.S
m_dbConnection.prepareStatement(查询)获取记录代码>第一次它将获取记录并完成处理,第二次它将检查我们称为同一语句的记录m_dbConnection.prepareStatement(query)代码>当我第二次调用时,我得到了java.sql.SQLException:连接已经关闭。
这是我获取连接的代码:
此方法调用以获取记录:
连接处于活动状态,但正在调用此
PreparedStatement ps=m_dbConnection.prepareStatement(sqlQuery)代码>
语句获取异常
请在下面找到完整的例外情况:
我的weblogic连接池配置:
您没有添加代码,因此很难知道问题出在哪里
我猜您添加了一些“finally”块,并关闭了连接-m\u dbConnection
所以你不能再使用它了。
只有在完成触摸数据库后才能尝试关闭。您没有添加代码,因此很难知道问题出在哪里
我猜您添加了一些“finally”块,并关闭了连接-m\u dbConnection
所以你不能再使用它了。
请仅在完成触摸数据库后尝试关闭。我想您已经检索了m_dbConnection
一次,并将其作为类中的成员变量保存com.orbitreasury.infrastructure.dbConnection
。相反,每次需要时都要检索连接。您不应该尝试优化连接池的工作。这是一项相当复杂的任务。连接池已经为您完成了这项工作。而不是
m_dbConnection.prepareStatement(templateSql)
使用
我想您已经检索了m_dbConnection
一次,并将其作为类com.orbitreasury.infrastructure.dbConnection
中的成员变量保存。相反,每次需要时都要检索连接。您不应该尝试优化连接池的工作。这是一项相当复杂的任务。连接池已经为您完成了这项工作。而不是
m_dbConnection.prepareStatement(templateSql)
使用
显示如何连接到数据库。这没问题。我的意思是在你连接到DB的地方显示你的代码。对不起,这是一个巨大的代码,我们不需要整个应用程序。只是连接到DB的部分。我想这只是几行代码。连接。他没有活着。错误消息是这样说的。通常,将连接作为成员变量是错误的。它应该在需要它作为局部变量的方法中获得,并在相同的方法中闭合。连接池将减轻开销。不要写你自己的。展示你如何连接到数据库。这没关系。我的意思是在你连接到DB的地方显示你的代码。对不起,这是一个巨大的代码,我们不需要整个应用程序。只是连接到DB的部分。我想这只是几行代码。连接。他没有活着。错误消息是这样说的。通常,将连接作为成员变量是错误的。它应该在需要它作为局部变量的方法中获得,并在相同的方法中闭合。连接池将减轻开销。不要写你自己的。:<为什么无故降级:(:<为什么无故降级:(
java.sql.SQLException: Connection has already been closed.
at weblogic.jdbc.wrapper.PoolConnection.checkConnection(PoolConnection.java:55)
at weblogic.jdbc.wrapper.Connection.preInvocationHandler(Connection.java:92)
at weblogic.jdbc.wrapper.Connection.prepareStatement(Connection.java:482)
at com.orbitreasury.infrastructure.DBConnection.getPreparedStatement(DBConnection.java:464)
at com.orbitreasury.moneymarket.businessimplementation.entity.RepriceEntity.getRepriceDeals(RepriceEntity.java:126)
at com.orbitreasury.moneymarket.businessimplementation.RepriceDeals.updateRepriceDeals(RepriceDeals.java:896)
at com.orbitreasury.moneymarket.eventhandler.RepriceJobEvent.processEvent(RepriceJobEvent.java:91)
at com.orbitreasury.common.control.NavigationController.processEvent(NavigationController.java:232)
at com.orbitreasury.common.control.NavigationController.onEvent(NavigationController.java:121)
at WebRequestController.processLocalRequest(WebRequestController.java:348)
at WebRequestController.doPost(WebRequestController.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3495)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
java.sql.SQLException: Connection has already been closed.
at weblogic.jdbc.wrapper.PoolConnection.checkConnection(PoolConnection.java:55)
at weblogic.jdbc.wrapper.Connection.preInvocationHandler(Connection.java:92)
at weblogic.jdbc.wrapper.Connection.prepareStatement(Connection.java:482)
at com.orbitreasury.infrastructure.DBConnection.getPreparedStatement(DBConnection.java:464)
at com.orbitreasury.moneymarket.businessimplementation.entity.RepriceEntity.getRepriceDeals(RepriceEntity.java:126)
at com.orbitreasury.moneymarket.businessimplementation.RepriceDeals.updateRepriceDeals(RepriceDeals.java:896)
at com.orbitreasury.moneymarket.eventhandler.RepriceJobEvent.processEvent(RepriceJobEvent.java:91)
at com.orbitreasury.common.control.NavigationController.processEvent(NavigationController.java:232)
at com.orbitreasury.common.control.NavigationController.onEvent(NavigationController.java:121)
at WebRequestController.processLocalRequest(WebRequestController.java:348)
at WebRequestController.doPost(WebRequestController.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3495)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
m_dbConnection.prepareStatement(templateSql)
getPoolConnection().prepareStatement(templateSql)