Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JDBC超时未引发SQLTimeoutException_Jdbc_Spring Jdbc - Fatal编程技术网

JDBC超时未引发SQLTimeoutException

JDBC超时未引发SQLTimeoutException,jdbc,spring-jdbc,Jdbc,Spring Jdbc,我试图在JDBC语句上设置查询超时,并期望它在超时时抛出SQLTimeoutException。 但我得到的是一个通用的SQLException,错误代码为ORA-01013 知道我错过了什么吗 我正在寻找一个DB独立的方式来处理超时。检查DB特定的错误代码在这方面可能没有帮助 顺便说一句,我通过Spring的JdbcTemplate设置这个属性 myStatement.setQueryTimeout(1); 投掷 java.sql.SQLException: ORA-01013: user

我试图在JDBC语句上设置查询超时,并期望它在超时时抛出SQLTimeoutException。 但我得到的是一个通用的SQLException,错误代码为ORA-01013

知道我错过了什么吗

我正在寻找一个DB独立的方式来处理超时。检查DB特定的错误代码在这方面可能没有帮助

顺便说一句,我通过Spring的JdbcTemplate设置这个属性

myStatement.setQueryTimeout(1);
投掷

java.sql.SQLException: ORA-01013: user requested cancel of current operation
编辑:这是错误的堆栈跟踪。我使用的是精简驱动程序(ojdbc6-11.2.0.1.0.jar)


这是驱动程序用来抛出异常/错误的代码,它不会将异常映射到SQLTimeoutException。这就是oracle驱动程序实现中的差距

提及

下面完整方法中的代码片段是

     DatabaseError.throwSqlException(this.meg.conv
                    .CharBytesToString(this.errorMsg, this.errorLength[0],
                            true), DatabaseError
                    .ErrorToSQLState(this.retCode), this.retCode);
完整的方法是这样的

/*     */
/*     */void processError(boolean paramBoolean,
        OracleStatement paramOracleStatement)
/*     */throws SQLException
/*     */{
    /* 303 */if (this.retCode != 0)
    /*     */{
        /* 311 */switch (this.retCode)
        /*     */{
        /*     */case 28:
            /*     */
        case 600:
            /*     */
        case 1012:
            /*     */
        case 3113:
            /*     */
        case 3114:
            /* 323 */this.connection.internalClose();
            /*     */}
        /*     */
        /* 328 */if (paramBoolean)
        /*     */{
            **/* 331 */
             *DatabaseError.throwSqlException(this.meg.conv
                    .CharBytesToString(this.errorMsg, this.errorLength[0],
                            true), DatabaseError
                    .ErrorToSQLState(this.retCode), this.retCode);*
            /*     */}
        /*     */else
        /*     */{
            /* 335 */return;
            /*     */}
        /*     */
        /*     */}
    /*     */
    /* 341 */if (!paramBoolean) {
        /* 342 */return;
        /*     */}
    /*     */
    /* 351 */if ((this.warningFlag & 0x1) == 1)
    /*     */{
        /* 353 */int i = this.warningFlag & 0xFFFFFFFE;
        /*     */
        /* 356 */if (((i & 0x20) == 32) || ((i & 0x4) == 4)) {
            /* 357 */throw DatabaseError.newSqlException(110);
            /*     */}
        /*     */}
    /*     */
    /* 361 */if ((this.connection != null)
            && (this.connection.plsqlCompilerWarnings))
    /*     */{
        /* 363 */if ((this.flags & 0x4) == 4)
            /* 364 */paramOracleStatement.foundPlsqlCompilerWarning();
        /*     */}
    /*     */}

不幸的是,JDBC驱动程序并不总是实现JDBC所需(或:建议)的一切。特别适用于“较新”的功能<代码>SQLTimeoutException是在Java6/JDBC4中添加的

这有两个含义:

  • 它在旧版本中不可用
  • 您需要一个用于JDBC4或更高版本的驱动程序
  • 还有其他的复杂情况:

  • 考虑到您问题中的特定错误消息(“ORA-01013:用户请求取消当前操作”),驱动程序可能根本无法区分用户实际发起的语句取消和超时发起的语句取消。在这种情况下,最好抛出最通用的异常类型

  • 如果一个供应商支持多个Java和JDBC版本,那么他们可能只是简单地采用快捷方式,并且只做最低限度的工作,以(几乎)兼容JDBC。这可能只包括抛出
    SQLException
    ,以使他们更容易使用相同的代码库,而不必大惊小怪


  • 证据?Stack trace?谢谢你sandeep。我想接下来我不得不求助于自己进行错误代码检查的肮脏方式。
    /*     */
    /*     */void processError(boolean paramBoolean,
            OracleStatement paramOracleStatement)
    /*     */throws SQLException
    /*     */{
        /* 303 */if (this.retCode != 0)
        /*     */{
            /* 311 */switch (this.retCode)
            /*     */{
            /*     */case 28:
                /*     */
            case 600:
                /*     */
            case 1012:
                /*     */
            case 3113:
                /*     */
            case 3114:
                /* 323 */this.connection.internalClose();
                /*     */}
            /*     */
            /* 328 */if (paramBoolean)
            /*     */{
                **/* 331 */
                 *DatabaseError.throwSqlException(this.meg.conv
                        .CharBytesToString(this.errorMsg, this.errorLength[0],
                                true), DatabaseError
                        .ErrorToSQLState(this.retCode), this.retCode);*
                /*     */}
            /*     */else
            /*     */{
                /* 335 */return;
                /*     */}
            /*     */
            /*     */}
        /*     */
        /* 341 */if (!paramBoolean) {
            /* 342 */return;
            /*     */}
        /*     */
        /* 351 */if ((this.warningFlag & 0x1) == 1)
        /*     */{
            /* 353 */int i = this.warningFlag & 0xFFFFFFFE;
            /*     */
            /* 356 */if (((i & 0x20) == 32) || ((i & 0x4) == 4)) {
                /* 357 */throw DatabaseError.newSqlException(110);
                /*     */}
            /*     */}
        /*     */
        /* 361 */if ((this.connection != null)
                && (this.connection.plsqlCompilerWarnings))
        /*     */{
            /* 363 */if ((this.flags & 0x4) == 4)
                /* 364 */paramOracleStatement.foundPlsqlCompilerWarning();
            /*     */}
        /*     */}