You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kawthar Bt M Sulaiman <mk...@maxis.com.my> on 2004/04/02 10:54:19 UTC

Re: Connection Pool setup.

Hello, 

I'd like to know how to implement connection pooling in my
application.
This is what I had done so far.  Pls let me know what I need to change

to use the pooling mechanism.

1.  I created a singleton class: DatabaseOperations.
2.  It has an Connection instance: conn.
3.  During initialization, it gets connection as follows:
     DataSource ds  = (DataSource)
ctx.lookup("java:comp/env/jdbc/mySQLDatabase");
     conn = ds.getConnection();

4.  I have several public operations method (e.g selectOperations(...),
insertOperations(...)).
5.  Let's say I'd like to perform a select statement.  Inside my
selectOperations(...):
     Statement stmt = conn.createStatement();
     ResultSet rs = stmt.executeQuery(...);
     <process the result>

     In my finally block, I have:
     rslt.close();
     stmt.close();

Questions:
1.  Do I need to code any different to enable the connection pooling?

2.  When I called ds.getConnection(), does it opens up several
connections for pooling
     or just one connection?

3.  Do I need to close conn every time as well?  Since conn is an
instance, 
     how does it gets connection everytime an operation method is
called? (insert, select, update).

That's all I have for now.  Thanks,
--Kawthar



Confidential information may be contained in this e-mail and any files transmitted with it ('Message'). If you are not the addressee indicated in this Message (or responsible for delivery of this Message to such person), you are hereby notified that any dissemination, distribution, printing or copying of this Message or any part thereof is strictly prohibited. In such a case, you should delete this Message immediately and advise the sender by return e-mail. Opinions, conclusions and other information in this Message that do not relate to the official business of Maxis shall be understood as neither given nor endorsed by Maxis.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org