Skip site navigation (1) Skip section navigation (2)

Re: connection pooling for postgres

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 for postgres
Date: 2007-01-11 15:21:44
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
On Thursday 11 January 2007 15:28, James Neff wrote:
> Greetings,

> Where can I find good instructions or a tutorial on how to do connection
> pooling for JDBC to a Postgres database on my client?

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" );
[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. 


In response to


pgsql-jdbc by date

Next:From: Dave CramerDate: 2007-01-11 15:32:37
Subject: Re: connection pooling for postgres
Previous:From: Mark LewisDate: 2007-01-11 15:10:48
Subject: Re: connection pooling for postgres

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group