DataSource and Connection

D

Daniel

Hi all,

I have been using javax.sql.DataSource to get a Connection to the database.
Since it's supposed to get a Connection from the pool, I am wondering once I
am finished with the Connection object, do I need to close it? How do I
return it to the pool?

Doing it the old way with Class.forName and DriverManager, once I got the
Connection and finished it I did indeed close the Connection.

How about with DataSource?

I am using:
1) Tomcat 5 and MySQL
2) Oracle 9i AS and 9i DB

Thanks in advance!
 
R

raymondwlees

Daniel said:
Since it's supposed to get a Connection from the pool, I am wondering once I
am finished with the Connection object, do I need to close it? How do I
return it to the pool?

For good practice, you still need to do conn.close() in finally block
to return the database connection to the pool. You just don't need to
write Class.forName to load the JDBC driver, and you get connection
from datasource instead of DriverManager.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top