java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

今天统计接口测试时发生以下异常:

java.lang.RuntimeException: org.springframework.dao.QueryTimeoutException:
### Error querying database.  Cause: java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

### The error may exist in class path resource [orm/mapper/NetTrffVehicleMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select to_char(yxqz,'YYYY') year,count(*) count         from (             select hpzl,hphm,yxqz,row_number() over(partition by hpzl,hphm order by gxsj desc) linenum             from xxx.yyyyyyyyy t2             where 1=1                 and t2.hpzl in ('02', '52')                 and t2.syxz = 'A'                 and t2.ccdjrq > sysdate - 1826                 and 7 > hdzk                 and regexp_like(t2.cllx, 'K43|K33|K26|K16|K31|K32|K34|K41|K42', 'i')                 and not regexp_like(t2.zt, 'B|C|D|E|G|I|J|L|M|O|P', 'i')         ) where linenum=1         group by to_char(yxqz,'YYYY')         order by 1
### Cause: java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

; ]; ORA-01013: 用户请求取消当前的操作
; nested exception is java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

org.springframework.dao.QueryTimeoutException:
### Error querying database.  Cause: java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

### The error may exist in class path resource [orm/mapper/NetTrffVehicleMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: select to_char(yxqz,'YYYY') year,count(*) count         from (             select hpzl,hphm,yxqz,row_number() over(partition by hpzl,hphm order by gxsj desc) linenum             from xxx.yyyyyyyyy t2             where 1=1                 and t2.hpzl in ('02', '52')                 and t2.syxz = 'A'                 and t2.ccdjrq > sysdate - 1826                 and 7 > hdzk                 and regexp_like(t2.cllx, 'K43|K33|K26|K16|K31|K32|K34|K41|K42', 'i')                 and not regexp_like(t2.zt, 'B|C|D|E|G|I|J|L|M|O|P', 'i')         ) where linenum=1         group by to_char(yxqz,'YYYY')         order by 1
### Cause: java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

; ]; ORA-01013: 用户请求取消当前的操作
; nested exception is java.sql.SQLTimeoutException: ORA-01013: 用户请求取消当前的操作

        at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:76)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
        at com.sun.proxy.$Proxy83.selectList(Unknown Source)
        at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
        at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
        at com.sun.proxy.

网上查了一下,各种解决办法,但是感觉都与我的不符。
因为我的这个异常产生是在进行统计查询时产生,但是,有一个统计接口是正常的,正常的统计接口所使用的sql比较简单,而产生异常的sql则比较复杂,所以我推测是由于查询时间过长,导致程序中设置的数据库连接时间超时,从而主动断开连接,才会产生这个SQLTimeoutException: ORA-01013: 用户请求取消当前的操作的异常,但是我又不是很确定,并且我看了以下程序中的各个配置文件对数据库的连接超时时间的设置,设置的超时时间都挺长的,所以找了很长时间。
后来灵光一闪,想到会不会是mybatis中的数据库连接设置了超时(程序框架用的是公司的,尚不熟悉),于是打开mybatis的配置文件,果然,mybatis中设置了数据库连接超时时间,并且只有5秒(),而统计的sql查询时间在10秒以上甚至更多,于是修改配置,总算解决了,以此记录一下。

mybatis 配置:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <!-- Globally enables or disables any caches configured in any mapper under this configuration -->
        <setting name="cacheEnabled" value="false"/>
        <!-- Sets the number of seconds the driver will wait for a response from the database -->
        <setting name="defaultStatementTimeout" value="180"/>
        <!--打印SQL语句到控制台 -->
        <setting name="logImpl" value="STDOUT_LOGGING"/>
    </settings>
    <!-- Continue editing here -->
</configuration>

你可能感兴趣的:(Exception,MyBatis)