近日,调试ibatis(版本:ibatis-2.3.4.726.jar)连接Timesten(TimesTen release 11.2.2.4.1)(驱动版本 ttjdbc6.jar); 数据源连接池 为c3p0(版本号为 C3p0-0.9.2.1)
Spring 框架(版本 Spring2.5.6)
在调用存储过程中,使用 super.getSqlMapClientTemplate().queryForObject(); 时,线程挂起,在里面做死循环处理。CPU 可飚100%。(注,连接oracle数据库可以执行)
使用super.getSqlMapClientTemplate().update()或是 super.getSqlMapClientTemplate().insert()时,可以执行成功。
后来下载了这些包的源码,最后问题定位在了 Ibatis 的 SqlExecutor 类中的
private ResultSet getFirstResultSet(StatementScope scope, Statement stmt) throws SQLException {
ResultSet rs = null;
boolean hasMoreResults = true;
while (hasMoreResults) {
rs = stmt.getResultSet();
if (rs != null) {
break;
}
hasMoreResults = moveToNextResultsIfPresent(scope, stmt);
}
return rs;
}
private boolean moveToNextResultsIfPresent(StatementScope scope, Statement stmt) throws SQLException {
boolean moreResults;
// This is the messed up JDBC approach for determining if there are more results
moreResults = !(((moveToNextResultsSafely(scope, stmt) == false) && (stmt.getUpdateCount() == -1)));
return moreResults;
}
在这段的stmt.getUpdateCount() == -1 判断为false。
对比oracle 驱动执行 与timesten 驱动执行,两者区别就在这个地方。oracle 返回true。可结束while 循环。
找到timesten驱动源码:执行这段
public synchronized int getUpdateCount()
/* */ throws SQLException
/* */ {
/* 953 */ if (Logger.isTracingOn()) {
/* 954 */ Logger.logln("*Statement.getUpdateCount()");
/* */ }
/* */
/* 957 */ validateStatement();
/* */
/* 962 */ if (!this.moreResults) {
/* 963 */ return -1;
/* */ }
/* */
/* 967 */ int i = -1;
/* */
/* 969 */ if (!this.hasResultSet) {
/* 970 */ i = getRowCount();
/* */ }
/* */ else {
/* 973 */ setWarning(new SQLWarning("Statement has a ResultSet"));
/* */ }
/* */
/* 976 */ return i;
/* */ }
int getRowCount()
/* */ throws SQLException
/* */ {
/* 1737 */ int i = 0;
/* */ try
/* */ {
/* 1740 */ i = this.OdbcApi.SQLRowCount(this.hStmt.getValue());
/* */ }
/* */ catch (JdbcOdbcSQLWarning localJdbcOdbcSQLWarning)
/* */ {
/* 1746 */ BigDecimal localBigDecimal = (BigDecimal)localJdbcOdbcSQLWarning.value;
/* 1747 */ i = localBigDecimal.intValue();
/* */ }
/* */
/* 1750 */ return i;
/* */ }
就是上述这句正常执行返回了0.
自此,想来应该是两者驱动程序处理这段代码之间的差异问题。至于其中是否可配置什么参数,避免。还没找到相关资料。
如果看到这里的朋友,有什么办法解决的,可以留个言。一起学习。谢谢