closing the Connection

hi what is the best way to close the conenction of JDBC, is it to use con.close() directly or use finalize() method..thanks
[144 byte] By [Eng.Mohammeda] at [2007-11-26 21:59:34]
# 1
conn.close();
lildavesflavaa at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
so what is the advantage of finalize() method ?
Eng.Mohammeda at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

the best way is to close the db connection in the finally block:

try{

Connection connection ...

}catch(Exception e){

e.printStacktrace();

}finally{

try{

if(connection!=null)

connection.close();

}catch(Exception ee){

ee.printStacktrace();

}

}

java_2006a at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4
thankswhat i want to use this connection in jsp page ?
Eng.Mohammeda at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
> so what is the advantage of finalize() method ?It is there so that if incompetent programmers fail to close the connection properly, something else may eventually do it.
DrClapa at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
> what i want to use this connection in jsp page ?What's the difference? You should still close it after you finish using it.
DrClapa at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
thanks a lot
Eng.Mohammeda at 2007-7-10 3:58:38 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...