wood burning stoves 2.0*
The moose likes JDBC and the fly likes Can't push 5 lacs records in mysql at once. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Can Watch "Can New topic
Author

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

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
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:-


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Moving to our JDBC forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41494
    
  53
Why are you using a PreparedStatement if you then proceed to feed it a concatenated string? You should be using pstmt.setString(..., ...) instead.


Ping & DNS - my free Android networking tools app
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
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
Marshal

Joined: Mar 22, 2005
Posts: 41494
    
  53
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

Joined: Mar 06, 2001
Posts: 13459

Pseudocode
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't push 5 lacs records in mysql at once.