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."
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: 35241
7
posted
0
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.