JDBC超时未引发SQLTimeoutException
我试图在JDBC语句上设置查询超时,并期望它在超时时抛出SQLTimeoutException。 但我得到的是一个通用的SQLException,错误代码为ORA-01013 知道我错过了什么吗 我正在寻找一个DB独立的方式来处理超时。检查DB特定的错误代码在这方面可能没有帮助 顺便说一句,我通过Spring的JdbcTemplate设置这个属性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
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中添加的 这有两个含义:
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();
/* */}
/* */}