Should I close a connection when using DataBase Pool?

J

JTL.zheng

database pool means that the conncetion can be used by other user.
so when I finish the job, should I call
conn.close();
after it as the old way?
 
S

Sebastian Millies

Am Thu, 08 Nov 2007 06:09:06 -0800 schrieb JTL.zheng:
database pool means that the conncetion can be used by other user.
so when I finish the job, should I call
conn.close();
after it as the old way?

Yes. However, you should refer to the documentation of
your pool library to be sure. E. g. it could be like this:
PooledConnection conn = Pool.getConnection();
....
conn.close()
where the implementation of PooledConnection#close()
may choose to return the connection to the pool.

-- Sebastian
 
W

Wojtek

Sebastian Millies wrote :
Am Thu, 08 Nov 2007 06:09:06 -0800 schrieb JTL.zheng:


Yes. However, you should refer to the documentation of
your pool library to be sure. E. g. it could be like this:
PooledConnection conn = Pool.getConnection();
...
conn.close()
where the implementation of PooledConnection#close()
may choose to return the connection to the pool.

As noted above, you should alwasy explicitly close connections (and
result sets, and cursors, and statements, and ...).

Some pool managers (proxool for example) will automatically clean up
connection resources such as statements and result sets.

And proxool will also close connections after a certain number of
seconds.
 
J

JTL.zheng

Thank you very much.
so I should close the connection however it will not be destoried but
be returned to tomcat.
 
E

Esmond Pitt

JTL.zheng said:
Thank you very much.
so I should close the connection however it will not be destoried but
be returned to tomcat.

Not to Tomcat: returned to the JDBC driver's connection pool.
 
J

JTL.zheng

is it not the web container like tomcat or weblogic implement the
database pool but the database driver itself like mysql's java
connector?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

JTL.zheng said:
is it not the web container like tomcat or weblogic implement the
database pool but the database driver itself like mysql's java
connector?

Usually it is the container that implements the connection pool.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top