This post is not about discouraging debugging your code. Hee Hee!!! This is one of the lessons I learned recently.
My issue:
I had to execute an SQL query and print the resultset. I was starting the implementation and I wanted to see the output of the query. We usually work on two machines. One for dev and another for test. So, I ran my program on my test machine and connected to that process through eclipse (Remote Debugging). I got a NullPointerException in the code when I started traversing through the resultset.
Code is something like this: (Dont look at the syntax)
Statement stmt = conn.CreateConnection();
ResultSet rs = stmt.executeQuery(“My SQL Query here.”);
while(rs.next()) {
I print the values here.
}
When I the ran the code, I got a NullPointerException in the while loop. ie. rs.next(). But, rs it NOT null. So, I tried invoking some other methods in rs. ie. rs.first(), rs.findColumn() and all. Result was either a NullPointerException or ResultSet already closed exception. I could not figure out what is going wrong. That exception was thrown from inside the ResultSet Object. As the jdbc driver I used is not open source, I could not look into it. I spent almost a day on this issue. Wasted some network bandwidth.. Pinged somebody.. tortured somebody.. disturbed somebody.. No help!!!
After some time, by mistake, I executed the code and I forgot to launch the debugger. To my surprise, my code went through like charm. Suddenly I remembered reading (while utilizing the network bandwidth) that the resultset might be garbage collected.
My guess: For some reason, my resultset got garbage collected when I was debugging. But when I ran the code, it worked fine.
If you know the exact answer, please leave a comment. You will be blessed in this life and next 🙂
Hi mani,
how are you doing. nice to get in touch with you and your blog…
I had seen your query about the ‘null pointer exception’ while execute the query in ecliplse… the problem seems that, the possibility of ‘out of memory’ in database drivers is higher in debug mode run due to the limited number of objects creation…same like your thoughts in garbage collection too… hope the following link will give some more discussion on this issue and the solution might be the connectin pooling concepts….
http://www.velocityreviews.com/forums/t128947-jdbc-out-of-memory-null-pointer-exception.html
Anna!! Neenga thaana?? Good to c ur comment. Will check it out.