The following code sample is inside a for loop that runs about 2 million times.
List<String> parameters = new LinkedList<String>();
stmt2 = null;
rs2= null;
//This is line 472
stmt2 = con.prepareStatement("select NAME from TABLE_NAME where FIELD="+ strId);
rs2 = stmt2.executeQuery();
while (rs2.next()) {
parameters.add(rs2.getString("NAME"));
}
stack trace:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:437)
at com.mysql.jdbc.Connection.clientPrepareStatement(Connection.java:2185)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4782)
at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4687)
at consistencyCheck.ConsistencyCheck.parameterCheck(ConsistencyCheck.java:472)
at consistencyCheck.ConsistencyCheck.performConsistencyCheck(ConsistencyCheck.java:316)
at consistencyCheck.ConsistencyCheck.main(ConsistencyCheck.java:198)
Please let me know if more information is required.
Thank you.
Thanks everyone for the answers. I will accept BalusC's answer since he answered first. Unfortunately I cant upvote any other answers due to not enough reputation :(
Just a side note to all who suggested to increase memory heap. Increasing the memory heap is something you should never do unless you are 100 % sure that is the only solution to your problem. For example in my problem increasing the heap might 'solve' the problem, but the underlying blunder still remains.