Here is what i have in server.xml in the context of my app
<Resource name="jdbc/postgresql" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/postgresql">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://IP.GOES.HERE.XX/db_name_goes_here</value>
</parameter>
<parameter>
<name>username</name>
<value>TheUserNameGoesHere</value>
</parameter>
<parameter>
<name>password</name>
<value>ThePasswordGoesHere</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>50</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
then my web.xml
<resource-ref>
<description>postgreSQL Datasource</description>
<res-ref-name>jdbc/postgresql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
The following class provides connections from the pool:
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
/**
* Class Pool provides pooled connections from JNDI data source.
*
*/
public class Pool {
/**
* Method Pool creates a database pool
*/
public Pool() {
System.err.println("Pool Initialized");
}
/**
* Method getConnection.
* @return Connection
*/
public static Connection getConnection() {
Connection cn = null;
try {
Context ctx = new InitialContext();
DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/postgresql");
if (ds != null) {
cn = ds.getConnection();
}
}
catch (Exception e) {
e.printStackTrace(System.err);
}
return cn;
}
}
And to get a connection and use it, just declare like:
Connection cn = Pool.getConnection();
And that's it!
On Fri, 2002-12-06 at 16:11, Dionisio Ruiz de Zarate wrote:
> Hello can anybody help me to configure one connection pool to postgresql
> from tomcat?
> and how can i use fron one java class?
> thanks
>
>
>
> --
> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>