Oracle executeBatch異常:ArrayIndexOutOfBoundsException

來源:互聯網
上載者:User

標籤: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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.