標籤:style blog http ar io color os 使用 sp
原文地址:http://yanwushu.sinaapp.com/oracle_executebatch_arrayindexoutofboundsexception/
使用jdbc介面PreparedStatement.executeBatch()向oracle中批量執行sql時候,出現異常ArrayIndexOutOfBoundsException,具體資訊如下:
java.lang.ArrayIndexOutOfBoundsException: -32413 at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2672) atoracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10688) atcom.keyi.xxx.dal.xx.importFile(PublicCustomerImportDao.java:107)
看樣子是oralcejdbc驅動內部setupBindBuffers方法中出現了數組越界異常,但是是什麼原因導致的此異常出現,一直沒有搞清楚。在網上找到一個文章,通過他的思路得到瞭解決方案。
文章內容如下:
The 10g driver apparently keeps a global serialnumber for all parameters in the entire batch, with a "short"variable. So you can have at most 32768 parameters in the batch. I was havingthe same exception because I have a INSERT statement with 42 parameters and mybatches can be as big as 1000 records, so 42000 > 32768 and this overflowsto a negative index. I reduced the batch factor to 100 to be safe, and all iswell. I guess your update DML should have a larger number of parameters perrecord, right? (My diagnostic of the bug is just deduction from the symptoms)
文章地址為:https://community.oracle.com/thread/599441?start=15&tstart=0
大體的意思是,oracle的preparedStatement批量執行sql時,對參數個數是有上限的(針對不同版本的oracle驅動,這個上限對不同的可能是不同的),這個參數個數的含義指addBatch的次數*每條sql中的參數個數。對於Oracle 10g的驅動來說,這個值可能是32768,所以編程時,addBatch的次數*每條sql中的參數個數應該小於這個值,否則報錯。
按照這個思路,將addBatch的數量減少,使每次executeBatch的參數值小於32768,發現異常解決。
Oracle executeBatch異常:ArrayIndexOutOfBoundsException