开发者社区> 问答> 正文

连接Oracle,java.sql.SQLRecoverableException: 关闭的连接

报错场景:

系统在运行一段时间后,如果长时间未操作的情况下,再次交互,控制台会出现如下错误:

java.sql.SQLRecoverableException: 关闭的连接
        at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5416) ~[ojdbc6-11.2.0.4.jar!/:11.2.0.4.0]
        at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1585) ~[ojdbc6-11.2.0.4.jar!/:11.2.0.4.0]
        at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1570) ~[ojdbc6-11.2.0.4.jar!/:11.2.0.4.0]
        at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94) ~[ojdbc6-11.2.0.4.jar!/:11.2.0.4.0]
        at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:98) ~[druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.vendor.OracleValidConnectionChecker.isValidConnection(OracleValidConnectionChecker.java:92) [druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.DruidAbstractDataSource.testConnectionInternal(DruidAbstractDataSource.java:1476) [druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:1482) [druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1407) [druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:1397) [druid-1.2.8.jar!/:1.2.8]
        at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:100) [druid-1.2.8.jar!/:1.2.8]
        at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) [spring-jdbc-5.3.26.jar!/:5.3.26]
        at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) [spring-jdbc-5.3.26.jar!/:5.3.26]
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) [spring-jdbc-5.3.26.jar!/:5.3.26]
        at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) [mybatis-spring-2.0.7.jar!/:2.0.7]
        at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) [mybatis-spring-2.0.7.jar!/:2.0.7]
        at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) [mybatis-3.5.10.jar!/:3.5.10]
        at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81) [mybatis-plus-extension-3.5.3.1.jar!/:3.5.3.1]
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) [mybatis-3.5.10.jar!/:3.5.10]
        at com.sun.proxy.$Proxy134.query(Unknown Source) [na:na]
        at sun.reflect.GeneratedMethodAccessor218.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
        at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49) [mybatis-3.5.10.jar!/:3.5.10]
        at com.github.yulichang.interceptor.MPJInterceptor.intercept(MPJInterceptor.java:76) [mybatis-plus-join-core-1.4.4.1.jar!/:na]
        at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62) [mybatis-3.5.10.jar!/:3.5.10]
        at com.sun.proxy.$Proxy134.query(Unknown Source) [na:na]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:151) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:145) [mybatis-3.5.10.jar!/:3.5.10]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) [mybatis-3.5.10.jar!/:3.5.10]
        at sun.reflect.GeneratedMethodAccessor217.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) [mybatis-spring-2.0.7.jar!/:2.0.7]
        at com.sun.proxy.$Proxy88.selectList(Unknown Source) [na:na]
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) [mybatis-spring-2.0.7.jar!/:2.0.7]
        at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.sun.proxy.$Proxy91.selectList(Unknown Source) [na:na]
        at com.baomidou.mybatisplus.core.mapper.BaseMapper.selectOne(BaseMapper.java:172) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627) [na:1.8.0_181]
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$DefaultMethodInvoker.invoke(MybatisMapperProxy.java:162) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) [mybatis-plus-core-3.5.3.1.jar!/:3.5.3.1]
        at com.sun.proxy.$Proxy91.selectOne(Unknown Source) [na:na]
        at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getOne(ServiceImpl.java:202) [mybatis-plus-extension-3.5.3.1.jar!/:3.5.3.1]
        at com.baomidou.mybatisplus.extension.service.IService.getOne(IService.java:320) [mybatis-plus-extension-3.5.3.1.jar!/:3.5.3.1]

相关依赖:


        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.8</version>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4</version>
        </dependency>

yam配置:

datasource:
    driver-class-name: oracle.jdbc.driver.OracleDriver
    url: jdbc:oracle:thin:@127.0.0.1:1521:XE
    username: root
    password: root
    type: com.alibaba.druid.pool.DruidDataSource
    # Druid属性配置
    druid:
      # 初始化时建立物理连接的个数
      initial-size: 12
      # 连接池的最小空闲数量
      min-idle: 6
      # 连接池最大连接数量
      max-active: 24
      # 获取连接时最大等待时间,单位毫秒,默认为-1,表示永不超时
      max-wait: -1
      # 从数据库链接池中获取后,进行校验,避免失效的链接被使用,造成错误
      test-on-borrow: false
      # 当连接使用完,调用commit或者rollback方法后,连接池会回收该连接
      test-on-return: false
      # 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
      test-while-idle: true
      # testWhileIdle的判断依据,单位毫秒
      time-between-eviction-runs-millis: 60000
      # 用来测试连接是否可用的SQL语句
      validation-query: "SELECT 1 FROM DUAL"

展开
收起
南方钥钥 2024-04-01 11:10:58 311 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
PostgresChina2018_樊文凯_ORACLE数据库和应用异构迁移最佳实践 立即下载
PostgresChina2018_王帅_从Oracle到PostgreSQL的数据迁移 立即下载
Oracle云上最佳实践 立即下载

相关镜像