java.sql.SQLException:连接已关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25160297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.sql.SQLException: Connection is closed
提问by Dunken
I am making a quartz thread application that is collect data from a table and insert it in another table after inserting it is updating the data base
but when i got the above error i got some of the data inserted twice in the table
我正在制作一个石英线程应用程序,它从一个表中收集数据并在插入后将其插入另一个表中正在更新数据库,
但是当我收到上述错误时,我在表中插入了两次数据
Note that :
1.I use Oracle DB
2.**OJDBC6.jarto connect**
3.all tables are in same schema
请注意:
1.我使用 Oracle DB
2. **OJDBC6.jar连接**
3. 所有表都在同一架构中
StackTrace:
堆栈跟踪:
java.sql.SQLException: Connection is closed.
at org.apache.commons.dbcp.PoolingDriver$PoolGuardConnectionWrapper.checkOpen(PoolingDriver.java:263)
at org.apache.commons.dbcp.PoolingDriver$PoolGuardConnectionWrapper.close(PoolingDriver.java:268)
at com.sender.gsm.dao.Dao.closeConnection(Dao.java:38)
at com.sender.gsm.dao.OutDataDao.insertData(OutDataDao.java:91)
at com.sender.gsm.jobs.DataHandler.execute(DataHandler.java:49)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
The close connection function is
关闭连接函数是
public void closeConnection(Connection conn) throws SQLException {
if (conn != null ) {
conn.close();
}
}
采纳答案by Santhosh
at com.sender.gsm.dao.Dao.closeConnection(Dao.java:38) at com.sender.gsm.dao.OutDataDao.insertData(OutDataDao.java:91)
在 com.sender.gsm.dao.Dao.closeConnection(Dao.java:38) 在 com.sender.gsm.dao.OutDataDao.insertData(OutDataDao.java:91)
From the stack traces ,you are closing the connection while performing the insert after select. try creating the new connection.
从堆栈跟踪中,您在选择后执行插入时正在关闭连接。尝试创建新连接。
You might have called for closeConnection()
method after select statement.So an exception is thrown at runtime when it tried to execute the query the connection is closed.
您可能closeConnection()
在 select 语句之后调用了方法。因此,当它尝试执行连接关闭的查询时,会在运行时抛出异常。
If you are using connection pooling, make sure have configured the maxIdle
and maxActive
parameters to the reasonable values
如果您使用连接池,请确保已将maxIdle
和maxActive
参数配置为合理的值