Hello, It is possible to close a connection in the same method (i.e. creating a statement + ResultSet,..). But when I am making several methods() within the same class to deal with different types of data + opening and closing the database, I cannot close it anymore with the close() method. Or is it better to open/close everytime you need to make a connection. I thought it was better to make a seperate method to close the connection. Here is my method to close the connection. The instance databaseConnection is declared as a global variabel in the class.
public void closeVeldDAO(){ // close connection
try{ if (databaseConnection != null){
databaseConnection.close(); System.out.println ("na connection.close"); } } catch(SQLException sqle){ System.err.println(sqle.getMessage()); } } When I refer to this method I'll get back a nullPointerException. Anybody any advice ? thanks, Kristof
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Kristof
Originally posted by Kristof Camelbeke: When I refer to this method I'll get back a nullPointerException.
When? or do you mean you do get a NullPointerException when you call the method? If you getting an actual error what is the error message? I dont see anything in there that could cause that Exception what do the method calls look like that call it. How do you open the connection? Is this an app or a servlet? If it's a servlet just open it in init and close it in destroy, in an app you could create a static variable to represent the connection then close it in finalize. sorry if this doesn't help too much but some info is needed. - I think.
Dave
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.