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

[BUG] 若不同线程同时使用相同的数据表进行查询,出现:Cause: java.sql.SQLException: Operation not allowed after ResultSet closed #6303

Open
umll opened this issue Dec 24, 2024 · 0 comments

Comments

@umll
Copy link

umll commented Dec 24, 2024

Database Type

MySQL

Database Version

MySQL 5.7

Druid Version

1.2.20

JDK Version

OpenJDK 8

Error SQL

    SQL1:
        select count(*) as totalCount, sum(topic_fraction) as totalScore
        from relate_test_topic rtt
                 left join relate_topicset_test rtt2 on rtt.test_id = rtt2.test_id
        where rtt2.topicset_id = #{topicsetId}
        group by rtt.test_id
    SQL2:
        select topic_typeid,
               topic_id,
               CONCAT(topic_typeid, '-', relate_test_topic.topic_number) as labels,
               topic_title                                               as topicName,
               topic_fraction
        from relate_test_topic
                 left join relate_topicset_test rtt on relate_test_topic.test_id = rtt.test_id
        where rtt.topicset_id = #{topicsetId}
          and topic_typeid in (6, 7)
        order by topic_typeid, topic_number
    SQL3:
        select ANY_VALUE(tp.test_name)        as test_name,
               rtt.topic_typeid,
               ANY_VALUE(tt.type_description) as type_description,
               count(rtt.topic_id)            as topic_count,
               sum(rtt.topic_fraction)        as topic_fraction
        from relate_test_topic rtt
                 left join relate_topicset_test rttt on rttt.test_id = rtt.test_id
                 left join test_paper tp on rtt.test_id = tp.test_id
                 left join topic_type tt on rtt.topic_typeid = tt.topic_typeid
        where rttt.topicset_id = #{topicsetId}
        group by rtt.topic_typeid

Testcase Code

我的配置:

  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    druid:
      # 可参照https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%88%97%E8%A1%A8
      url: jdbc:mysql://10.6.3.111:3307/oj_new?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true&rewriteBatchedStatements=true&allowMultiQueries=true
      username: root
      password: jsuoj123
      # 初始连接数
      initialSize: 5
      # 最小连接池数量
      minIdle: 10
      # 最大连接池数量
      maxActive: 20
      # 配置获取连接等待超时的时间
      maxWait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      timeBetweenEvictionRunsMillis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      minEvictableIdleTimeMillis: 300000
      # 配置一个连接在池中最大生存的时间,单位是毫秒
      maxEvictableIdleTimeMillis: 900000
      # 配置检测连接是否有效
      validationQuery: SELECT 1 FROM DUAL
      testWhileIdle: true
      testOnBorrow: false
      testOnReturn: false
      webStatFilter:
        enabled: true
      statViewServlet:
        enabled: true
        allow:
        url-pattern: /druid/*
        # 控制台管理用户名和密码
        login-username: jusoj
        login-password: 123456
      filter:
        stat:
          enabled: true
          # 慢SQL记录
          log-slow-sql: true
          slow-sql-millis: 400
          merge-sql: true
        wall:
          config:
            multi-statement-allow: true

Stacktrace Info

No response

Error Info

2024-12-24 11:24:44.859 ERROR 1994 --- [nio-8080-exec-8] c.j.o.q.handle.GlobalExceptionHandler : 未知异常!

org.springframework.dao.TransientDataAccessResourceException:

Error querying database. Cause: java.sql.SQLException: Operation not allowed after ResultSet closed

The error may exist in file [/home/ojhome/tomcat9/webapps/query/WEB-INF/classes/mapper/SubmitSubjectMapper.xml]

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT rtu.usergroup_id FROM relate_usergroup_user ruu JOIN relate_topicset_usergroup rtu ON rtu.usergroup_id = ruu.usergroup_id WHERE ruu.account_id = ? AND rtu.topicset_id = ? limit 1

Cause: java.sql.SQLException: Operation not allowed after ResultSet closed

; Operation not allowed after ResultSet closed; nested exception is java.sql.SQLException: Operation not allowed after ResultSet closed
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:110)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:70)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:79)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:439)
at com.sun.proxy.$Proxy77.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:89)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:152)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
at com.sun.proxy.$Proxy82.getUsergroupId(Unknown Source)

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

1 participant