Re: Connection pooling in java

From: "Ido M(dot) Tamir" <tamir(at)imp(dot)univie(dot)ac(dot)at>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Connection pooling in java
Date: 2006-12-22 10:34:03
Message-ID: 200612221134.03450.tamir@imp.univie.ac.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Friday 22 December 2006 09:02, janaka priyadarshana wrote:

http://www.mchange.com/projects/c3p0/index.html

c3p0 was designed to be butt-simple to use. Just put the jar file
[lib/c3p0-0.9.0.jar] in your application's effective CLASSPATH, and make a
DataSource like this:

import com.mchange.v2.c3p0.*;

...

ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "org.postgresql.Driver" ); //loads the jdbc driver
cpds.setJdbcUrl( "jdbc:postgresql://localhost/testdb" );
cpds.setUser("dbuser");
cpds.setPassword("dbpassword");

[Optional] If you want to turn on PreparedStatement pooling, you must also set
maxStatements and/or maxStatementsPerConnection(both default to 0):

cpds.setMaxStatements( 180 );

Do whatever you want with your DataSource, which will be backed by a
Connection pool set up with default parameters. You can bind the DataSource
to a JNDI name service, or use it directly, as you prefer.
When you are done, you can clean up the DataSource you've created like this:

DataSources.destroy( cpds );

That's it! The rest is detail.

hth
ido

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Guy Rouillier 2006-12-22 17:47:20 Re: Connection pooling in java
Previous Message Steve Langridge 2006-12-22 08:35:55 BUG #2856: Jdbc 4 connector running on JDK 1.6 should not raise exception for getClientInfo/setClientInfo