Wednesday, April 25, 2007

Database Exception Fixed

Today, I tried to do some unit tests but could not solve the problem "can't find the module". Then I stopped working on unit test and try to solve the database exception "The result set is closed".

Before I spent a lot of time on the database exception but couldn't solved it. I almost gave up. But because today Gary didn't finish the stored procedure, so I had nothing to do. I decided to look at the database exception again. I spent about one and a half hours searching on Google about the problem but couldn't find any solution. Finally, I did something that didn't make sense but it solved the problem.

In a DatabaseConnector class, I defined the connection, statement, and the resultSet as a global variable and set them to null. I used these variable in all methods that called the stored procedure. In each method I had an try, catch, finally blocks. In the finally block, it would closed the resultset, connection, statement if they were null.

What I did to solve the problem was to change those global variables to local variables. This made the code look so ugly since all method used that same variables which can be define as global. However, it fixed the problem (I hoped). I tested the application several times and it seemed like the problem got fixed. Because I didn't understand the root cause of the problem, I was sure if this solved the problem. Maybe I have to learn more about JDBC.

No comments: