Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 4903B9FA372 for ; Thu, 11 Jan 2007 11:32:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 46011-07 for ; Thu, 11 Jan 2007 11:32:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id CD1609FA2A6 for ; Thu, 11 Jan 2007 11:32:29 -0400 (AST) Received: (qmail 28878 invoked from network); 11 Jan 2007 15:32:28 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.14?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 11 Jan 2007 15:32:28 -0000 In-Reply-To: <200701111621.44374.tamir@imp.univie.ac.at> References: <45A64978.3090305@tethyshealth.com> <200701111621.44374.tamir@imp.univie.ac.at> Mime-Version: 1.0 (Apple Message framework v752.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: pgsql-jdbc@postgresql.org Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: connection pooling for postgres Date: Thu, 11 Jan 2007 10:32:37 -0500 To: Ido M. Tamir X-Mailer: Apple Mail (2.752.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/80 X-Sequence-Number: 16445 This is another good option. On 11-Jan-07, at 10:21 AM, Ido M. Tamir wrote: > 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? > > 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 > > ---------------------------(end of > broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org >