but I can't close the connection in each query... the connection is used by other objects... I have a DAO for each class that needs access to the DB... but some of these DAOs are Singletons, so several objects can use one DAO and one connection to the db... so I can't just close it whenever I want... .:| Christian J. Dechery .:| FINEP - Depto. de Sistemas .:| [EMAIL PROTECTED] .:| (21) 2555-0332
>>> [EMAIL PROTECTED] 11/06/02 11:12 >>> finalize() gets called on garbage collection. Which may occur a long time from when your are done with your connection. Which isn't the time to close your db connections - it should be done much earlier. Here is code I typically use: Connection con = null; PreparedStatement stmt = null; ResultSet rs = null; try { con = magicalConnectionGetter(); stmt = magicalStatementGetter(); rs = magicalResultSetGetter(); } catch(Throwable e) { //do as needed } finally { try {if (rs!=null) rs.close();}catch(Throwable e){} try {if (stmt!=null) stmt.close();}catch(Throwable e){} try {if (con!=null) con.close();}catch(Throwable e){} } Always use finally to close your database assets - it will save much heartache later. finally blocks always gets run - even if you issue a return in the try block. -Tim Christian J. Dechery wrote: > I'm experiencing here a pretty serious problem, that we can't get trough... > > We have several classes accessing and connecting via the oracle native driver... but >so it happens, some of these connections aren't properly closed when the class "dies" >(meaning, the execution of the JSP ends). > > I've even debugged it, there are some JSPs that opens like 4 connections, and in my >finalize() method there's a con.close() call, never all the 4 con.close() are >successfull, there's always at least one that fails and gives an execption. I don't >know why. > > Would that "JDBC Realm" thing help that? What is that anyway, could someone explain >to me? > > thanks > > .:| Christian J. Dechery > .:| FINEP - Depto. de Sistemas > .:| [EMAIL PROTECTED] > .:| (21) 2555-0332 > > -- To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED] > For additional commands, e-mail: < mailto:[EMAIL PROTECTED] >