使用准备好的语句迭代 sql resultSet 时出现 ArrayIndexOutOfBoundsException

ArrayIndexOutOfBoundsException while iterating sql resultSet with prepared statement

我在获取结果集时遇到以下错误。我正在使用 jdbc 瘦驱动程序 (ojdbc6)。有趣的是,它在处理 10 行 后给出了错误。我查看了一些论坛,发现 jdbc 驱动程序存在一些问题。我想知道我是否可以用这个驱动程序 (ojdbc6) 本身做点什么!!

在此方面提供任何帮助,我们将不胜感激。

这是 table 结构:

CREATE TABLE "TEST_SO_MANY_COLUMNS" 
   (    "COL1" VARCHAR2(4000 BYTE), 
    "COL2" VARCHAR2(4000), 
    "COL3" VARCHAR2(4000), 
    "COL4" VARCHAR2(4000), 
    "COL5" VARCHAR2(4000), 
    "COL6" VARCHAR2(4000), 
    "COL7" VARCHAR2(4000), 
    "COL8" VARCHAR2(4000), 
    "COL9" VARCHAR2(4000), 
    "COL10" VARCHAR2(4000), 
    "COL11" VARCHAR2(4000), 
    "COL12" VARCHAR2(4000), 
    "COL13" VARCHAR2(4000), 
    "COL14" VARCHAR2(4000), 
    "COL15" VARCHAR2(4000), 
    "COL16" VARCHAR2(4000), 
    "COL17" VARCHAR2(4000), 
    "COL18" VARCHAR2(4000), 
    "COL19" VARCHAR2(4000), 
    "COL20" VARCHAR2(4000), 
    "COL21" VARCHAR2(4000), 
    "COL22" VARCHAR2(4000), 
    "COL23" VARCHAR2(4000), 
    "COL24" VARCHAR2(4000), 
    "COL25" VARCHAR2(4000), 
    "COL26" VARCHAR2(4000), 
    "COL27" VARCHAR2(4000), 
    "COL28" VARCHAR2(4000), 
    "COL29" VARCHAR2(4000), 
    "COL30" VARCHAR2(4000), 
    "COL31" VARCHAR2(4000), 
    "COL32" VARCHAR2(4000), 
    "COL33" VARCHAR2(4000), 
    "COL34" VARCHAR2(4000), 
    "COL35" VARCHAR2(4000), 
    "COL36" VARCHAR2(4000), 
    "COL37" VARCHAR2(4000), 
    "COL38" VARCHAR2(4000), 
    "COL39" VARCHAR2(4000), 
    "COL40" VARCHAR2(4000), 
    "COL41" VARCHAR2(4000), 
    "COL42" VARCHAR2(4000), 
    "COL43" VARCHAR2(4000), 
    "COL44" VARCHAR2(4000), 
    "COL45" VARCHAR2(4000), 
    "COL46" VARCHAR2(4000), 
    "COL47" VARCHAR2(4000), 
    "COL48" VARCHAR2(4000), 
    "COL49" VARCHAR2(4000), 
    "COL50" VARCHAR2(4000), 
    "COL51" VARCHAR2(4000), 
    "COL52" VARCHAR2(4000), 
    "COL53" VARCHAR2(4000), 
    "COL54" VARCHAR2(4000), 
    "COL55" VARCHAR2(4000), 
    "COL56" VARCHAR2(4000), 
    "COL57" VARCHAR2(4000), 
    "COL58" VARCHAR2(4000), 
    "COL59" VARCHAR2(4000), 
    "COL60" VARCHAR2(4000), 
    "COL61" VARCHAR2(4000), 
    "COL62" VARCHAR2(4000), 
    "COL63" VARCHAR2(4000), 
    "COL64" VARCHAR2(4000), 
    "COL65" VARCHAR2(4000), 
    "COL66" VARCHAR2(4000), 
    "COL67" VARCHAR2(4000), 
    "COL68" VARCHAR2(4000), 
    "COL69" VARCHAR2(4000), 
    "COL70" VARCHAR2(4000), 
    "COL71" VARCHAR2(4000), 
    "COL72" VARCHAR2(4000), 
    "COL73" VARCHAR2(4000), 
    "COL74" VARCHAR2(4000), 
    "COL75" VARCHAR2(4000), 
    "COL76" VARCHAR2(4000), 
    "COL77" VARCHAR2(4000), 
    "COL78" VARCHAR2(4000), 
    "COL79" VARCHAR2(4000), 
    "COL80" VARCHAR2(4000), 
    "COL81" VARCHAR2(4000), 
    "COL82" VARCHAR2(4000), 
    "COL83" VARCHAR2(4000), 
    "COL84" VARCHAR2(4000), 
    "COL85" VARCHAR2(4000), 
    "COL86" VARCHAR2(4000), 
    "COL87" VARCHAR2(4000), 
    "COL88" VARCHAR2(4000), 
    "COL89" VARCHAR2(4000), 
    "COL90" VARCHAR2(4000), 
    "COL91" VARCHAR2(4000), 
    "COL92" VARCHAR2(4000), 
    "COL93" VARCHAR2(4000), 
    "COL94" VARCHAR2(4000), 
    "COL95" VARCHAR2(4000), 
    "COL96" VARCHAR2(4000), 
    "COL97" VARCHAR2(4000), 
    "COL98" VARCHAR2(4000), 
    "COL99" VARCHAR2(4000), 
    "COL100" VARCHAR2(4000), 
    "COL101" VARCHAR2(4000), 
    "COL102" VARCHAR2(4000), 
    "COL103" VARCHAR2(4000), 
    "COL104" VARCHAR2(4000), 
    "COL105" VARCHAR2(4000), 
    "COL106" VARCHAR2(4000), 
    "COL107" VARCHAR2(4000), 
    "COL108" VARCHAR2(4000), 
    "COL109" VARCHAR2(4000), 
    "COL110" VARCHAR2(4000), 
    "COL111" VARCHAR2(4000), 
    "COL112" VARCHAR2(4000), 
    "COL113" VARCHAR2(4000), 
    "COL114" VARCHAR2(4000), 
    "COL115" VARCHAR2(4000), 
    "COL116" VARCHAR2(4000), 
    "COL117" VARCHAR2(4000), 
    "COL118" VARCHAR2(4000), 
    "COL119" VARCHAR2(4000), 
    "COL120" VARCHAR2(4000)
   );

Table 大约有 200 行,所有列的值最多为 4000 个字符。

查询格式:

select "COL1","COL2","COL3" ......."COL120" from SRC."TEST_SO_MANY_COLUMNS"

代码片段:

 Statement sel_stmt = connection.createStatement();
 ResultSet res = sel_stmt.executeQuery(query);
 res.setFetchSize(10000);
 ResultSetMetaData resultSetMetaData = resultSet.getMetaData();

获取结果集时未收到任何错误。迭代结果集时出现问题:

int count = 0;
if (resultSet.next()) {
    count++ ;
    //Do Something i.e. resultSet.getObject() .. and so on.. 
}
// Do something 

上面的迭代对前 10 行工作正常,但之后出现以下异常。错误的堆栈跟踪:

java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at oracle.jdbc.driver.T4CVarcharAccessor.saveDataFromOldDefineBuffers(T4CVarcharAccessor.java:411)
    at oracle.jdbc.driver.T4CStatement.saveDefineBuffersIfRequired(T4CStatement.java:533)
    at oracle.jdbc.driver.OracleStatement.prepareAccessors(OracleStatement.java:1070)
    at oracle.jdbc.driver.OracleStatement.check_row_prefetch_changed(OracleStatement.java:3080)
    at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:321)
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:277)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这是一个很老的错误 (4751145)。它在 2005 年的 10.2 驱动程序中被报道。 10.2.0.3 驱动程序已修复。我的猜测是您 运行 要么是 10.2.0.1 要么是 10.2.0.2。

Oracle 下载页面在这里: http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html

如果你想坚持使用 10.2 代码线,那么你应该移动到最新的补丁集 10.2.0.5。请注意,该驱动程序是向后兼容的,因此您还可以使用 11.2 甚至 12.1 驱动程序连接到 10g 数据库。