• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't push 5 lacs records in mysql at once.

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to push 5 lacs records in a single go as my requirement says that to me.
I'm getting hea space error.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.ensureCapacity(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at com.mysql.jdbc.ConnectionImpl.closeAllOpenStatements(ConnectionImpl.java:1583)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4381)
at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1564)
at example.fun.DbConnection.main(DbConnection.java:64)


Is there any way to resolve this issue ?


My sample code is:-
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our JDBC forum.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using a PreparedStatement if you then proceed to feed it a concatenated string? You should be using pstmt.setString(..., ...) instead.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Why are you using a PreparedStatement if you then proceed to feed it a concatenated string? You should be using pstmt.setString(..., ...) instead.


wats the big deal in that ?
Any specific reason?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fact that you're creating lots of unnecessary string objects in what is obviously a low-memory situation should be reason enough.

But you're also throwing away all the benefits of prepared statements. The way you're using it, you might as well use a regular Statement.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pseudocode
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic