tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kawthar Bt M Sulaiman" <>
Subject RE: Connection Pool setup.
Date Sat, 03 Apr 2004 02:08:47 GMT

Hi Kal,

Thank you... your getConnection() and releaseConnection() also very
Will implement and test them... 


>>> 02/04/2004 08:47:43 PM >>>


I'd like to know how to implement connection pooling in my
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)
     conn = ds.getConnection();

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

     In my finally block, I have:

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?
	Depends on how you have it configured. maxActive and maxIdle
settings for the resource.

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

	Yes, you have to close the connection each time, which returns
the connection to the pool for
other processes to use. 

I have the following methods in my generic DataBase Operations class.
    static public Connection getConnection() throws SQLException {
        Connection conn = null;
            conn = ds.getConnection();
        catch (Exception e) {
        return conn;

    static public void releaseConnection(Connection con){
        if (con != null)
        catch (Exception e) {

which get and close my connections for me. So, when I am in the
selectOperations(..) I call the getConnetion()
to get a connection and in the finally block I call the
releaseConnection() method.

Hope this helps.

CONFIDENTIALITY NOTE:  All e-mail sent to or from this address will be
received by the Waterfield Group corporate e-mail system and is subject
to archival, monitoring, and/or review by someone other than the
recipient or the sender.

This e-mail and any of its attachments may contain proprietary
information, which is privileged and confidential.  This e-mail is
intended solely for the use of the individual or entity to which it is
addressed.  If you are not the intended recipient of this e-mail, you
are hereby notified that any dissemination, distribution, copying, or
action taken in relation to the contents of and attachments to this
e-mail is strictly prohibited and may be unlawful.  If you have received
this e-mail in error, please notify the sender immediately and
permanently delete the original and any copy of this e-mail and any
printout.  Thank you.

To unsubscribe, e-mail: 
For additional commands, e-mail: 

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:
For additional commands, e-mail:

View raw message