0

Hello,

I get a out of memory error on line 4:

int isDeleted = 0;
               PreparedStatement psDeleteRecord=null;
               try {
                   psDeleteRecord=con.prepareStatement(delQuery);
                   isDeleted = psDeleteRecord.executeUpdate();
                   if(isDeleted !=1){
                       echoLog("Could not Delete: " + delQuery);
                   }
                   else {
                       numDel++;                        
                   }
               }
               catch (SQLException s) {
                  echoLog("Failed: " + delQuery);
                  s.printStackTrace();
               }

This block of code inside a while loop. Could some one explain to me why I am getting this error? Isn't PreparedStatement psDeleteRecord destroyed every time I loop?

The Error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
	at net.sourceforge.jtds.jdbc.RequestStream.<init>(RequestStream.java:72)
	at net.sourceforge.jtds.jdbc.SharedSocket.getRequestStream(SharedSocket.java:409)
	at net.sourceforge.jtds.jdbc.TdsCore.<init>(TdsCore.java:440)
	at net.sourceforge.jtds.jdbc.JtdsStatement.<init>(JtdsStatement.java:176)
	at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.<init>(JtdsPreparedStatement.java:99)
	at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareStatement(ConnectionJDBC2.java:2456)
	at net.sourceforge.jtds.jdbc.ConnectionJDBC2.prepareStatement(ConnectionJDBC2.java:2414)
	at monmouthpics.Main.main(Main.java:63)
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by javaAddict
0

SOME THING GOING INDEFINITELY WITHOUT CLOSING OR END UP...

you may close the connection after executing and validate every thing...

it might resolve your problem...

0

You are not closing the prepared statement. Also you'd better post the entire code along with the loop and how you pass values to the statement as well as the query.
I think there might be a better way to do this

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.