Re: Best Practice to Create a Connection Pool in PostgreSQL - Mailing list pgsql-jdbc

From Greg James
Subject Re: Best Practice to Create a Connection Pool in PostgreSQL
Date
Msg-id 4CCDCC902ACE4F27A8A526B67C510535@Serotonin
Whole thread Raw
In response to Re: Best Practice to Create a Connection Pool in PostgreSQL  (John R Pierce <pierce@hogranch.com>)
Responses Re: Best Practice to Create a Connection Pool in PostgreSQL
List pgsql-jdbc
Thanks for the advice.

Because I'm using Apache Tomcat 6, I ended up using the built-in Jakarta
Commons DBCP to create a connection pool to Postgres.  Not sure if this is a
best practice or not, but it appears to be working well.

For those interested in doing this on Tomcat, but don't know where to start,
my setup is below.

Thanks to those who provided the examples I found on the web and the text
"Professional Apache Tomcat 6" from Wrox.

I created a file "context.xml" in my web app's META-INF directory with the
following information:

<Context path="/your_web_app_name">
  <Resource name="jdbc/YourPool"
    auth="Container"
    type="javax.sql.DataSource"
    maxActive="100"
    maxIdle="30"
    maxWait="20000"
    removeAbandoned="true"
    removeAbandonedTimeout="120"
    username="username"
    password="password"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://your_server_ip:5432/your_postgres_database_name"
  />
</Context>

From a java class you can access the connection pool by using the following
imports...

import java.sql.*;
import javax.sql.*;
import javax.naming.*;

...and java code wrapped in a try/catch block...

String dsString = "java:/comp/env/jdbc/YourPool";
DataSource ds = (DataSource) new InitialContext().lookup(dsString);
Connection con = ds.getConnection();

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of John R Pierce
Sent: Tuesday, September 16, 2008 7:58 PM
To: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] Best Practice to Create a Connection Pool in PostgreSQL

Greg James wrote:
>
> Hi,
>
> I've been looking through the mail archives in the JDBC forum and have
> seen a number of different ways to create a JDBC connection pool to
> Postgres. Could someone point me in the right direction, eg
> Jdbc3ConnectionPool, Apache's DBCP, etc.?
>


One reason there are so many ways is that there are different
requirements for connection pools.


--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc


pgsql-jdbc by date:

Previous
From: John R Pierce
Date:
Subject: Re: Best Practice to Create a Connection Pool in PostgreSQL
Next
From: Guillaume Cottenceau
Date:
Subject: Re: Informacion del JDBC