Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation not allowed after ResultSet closed #1656

Closed
yuankui opened this issue Mar 24, 2017 · 8 comments
Closed

Operation not allowed after ResultSet closed #1656

yuankui opened this issue Mar 24, 2017 · 8 comments

Comments

@yuankui
Copy link

yuankui commented Mar 24, 2017

我在用jdbc对数据库进行dump,可以理解就是 select * from table1 limit 100 where id > xxx,不断的从数据库批量取数据

连接池管理用的druid(这也许是个错),然后不知道为什么,在线上跑一段时间就会报

java.sql.SQLException: Operation not allowed after ResultSet closed
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
	at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:799)
	at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:847)
	at com.mysql.jdbc.ResultSetImpl.getObject(ResultSetImpl.java:4877)
	at com.alibaba.druid.pool.DruidPooledResultSet.getObject(DruidPooledResultSet.java:439)

刚开始怀疑是mysql JDBC driver的问题
查了很多资料,最后发现一个人跟我情况类似,下面有个回答说,你是不是用了dbcp?
我后来想想,我也是用了druid来做连接池.

然后我后来弃用了druid,错误果然就没有报了.

所以我怀疑,druid是不是在我不期望的情况下关闭了我的数据库连接?

以下是我的druid配置

 DruidDataSource dataSource = new DruidDataSource();
    
    dataSource.setUrl(url);

    // 设置属性
    dataSource.setMaxActive(2);
    dataSource.setInitialSize(1);
    dataSource.setMaxWait(5000);
    dataSource.setMinEvictableIdleTimeMillis(30000);
    dataSource.setMaxEvictableIdleTimeMillis(300000);
    dataSource.setPoolPreparedStatements(true);
    dataSource.setTestWhileIdle(true);
    dataSource.setTestOnBorrow(false);
    dataSource.setTestOnReturn(false);
    dataSource.setPhyTimeoutMillis(1800000);
    dataSource.setRemoveAbandoned(true);
    dataSource.setRemoveAbandonedTimeout(180);
    dataSource.setValidationQuery("select 1");
    dataSource.setValidationQueryTimeout(1);
    dataSource.setTimeBetweenEvictionRunsMillis(10000);
    dataSource.setDefaultAutoCommit(true);
    dataSource.setConnectionProperties("connectTimeout=1000;socketTimeout=3000");
@wenshao
Copy link
Member

wenshao commented Mar 25, 2017

为什么要在关闭的ResultSet对象上做操作?

@yuankui
Copy link
Author

yuankui commented Mar 28, 2017

我没有手动关闭,我一直在next()取数据,取着取着就被关闭了.
不太清楚是不是druid关闭的. 线下问题复现不了,线上数据量大,持续时间长的时候就会出现这种错误.

@magicbest
Copy link

magicbest commented Jul 19, 2017

我也遇到了相同的情况,一次获取大量数据(大约一分钟后返回),时间长了就报相同的错。最后发现应该是链接超时的问题

@juneryo
Copy link

juneryo commented Apr 11, 2018

我这里也遇到了类似的问题

err

看上去是因为用到了Log4j2AsyncLogger的原因

@zhouguanglong1
Copy link

dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(180);
问题出在这两个属性的设置

@yuankui yuankui closed this as completed Feb 20, 2019
@lione0
Copy link

lione0 commented May 7, 2019

我没有手动关闭,我一直在next()取数据,取着取着就被关闭了.
不太清楚是不是druid关闭的. 线下问题复现不了,线上数据量大,持续时间长的时候就会出现这种错误.

请问最后如何解决的

@yuankui
Copy link
Author

yuankui commented May 15, 2019

dataSource.setRemoveAbandoned(true);
dataSource.setRemoveAbandonedTimeout(180);
问题出在这两个属性的设置

@lione0 试试这个

@yangmengmeng01
Copy link

使用mysql, 到底怎么解决的啊?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants