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)

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...

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 article has been dead for over six months. Start a new discussion instead.