JDBC Batch Insert OutOfMemoryError

前端 未结 2 1573
心在旅途
心在旅途 2020-12-08 20:21

I have written a method insert() in which I am trying to use JDBC Batch for inserting half a million records into a MySQL database:



        
2条回答
  •  盖世英雄少女心
    2020-12-08 21:08

    It is out of memory because it hold all the transaction in memory and only send it over to the database when you call executeBatch.

    If you don't need it to be atomic and would like the get better performance, you can keep a counter and call executeBatch every n number of records.

提交回复
热议问题