I have configured my web app to use tomcat's connection pooling.

and also I have modfied the default value of the factory attribute:
factory="org.apache.commons.dbcp.BasicDataSourceFactory"

Here is the context.xml
<Context>
        <Resource 
                name="jdbc/testDB" 
                factory="org.apache.commons.dbcp.BasicDataSourceFactory"
                auth="Container" 
                type="javax.sql.DataSource" 
                maxActive="10" 
                maxIdle="5" 
                maxWait="10000" 
                removeAbandoned="true"
                removeAbandonedTimeout="60"
                logAbandoned="true"
                username="username" 
                password="password" 
                driverClassName="com.mysql.jdbc.Driver" 
                url="jdbc:mysql://localhost:3306/test" />
</Context>


Here is how I retrieve the data source so that I later can ask for a
connection:


        private static BasicDataSource ds = null;

        public static DataSource getDataSource() throws SQLException {
                if (ds == null) {
                        try {
                                final Context initContext = new 
InitialContext();
                                ds = 
(BasicDataSource)initContext.lookup("java:/comp/env/jdbc/testDB");
                                initContext.close();
                                logDataSource(ds);
                                return ds;
                        } catch (final NamingException e) {
                                e.printStackTrace();
                                throw new RuntimeException("Java naming 
exception when getting
connection from tomcat pool: " + e.getMessage());
                        }
                } else {
                        logDataSource(ds);
                        return ds;
                }
    }



I have read somewhere that you have to create a PoolingDataSource if you
want
use connection pooling.

Here is a sample code that I have found:
GenericObjectPool connectionPool = new GenericObjectPool(null);
DriverManagerConnectionFactory connectionFactory = new
DriverConnectionFactory("jdbc:some:connect:string",null);
PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
PoolingDataSource dataSource = new PoolingDataSource(connectionPool);



Question:
When getting the DataSource (Or BasicDataSource in my case) from tomcat's
JNDI/JDBC service
does Tomcat manage the connection pooling itself.

Do I just need to retrieve the DataSource and then get the Connection and
close the Connection
after usage?

Or do I have to include a few lines of complicated as above as well?


Thanks!

-- 
View this message in context: 
http://www.nabble.com/Tomcat-5.5%2C-connection-pooling-with-commons-dbcp-1.2.1-tp19204896p19204896.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to