Re: connection pool to postgresql

2002-12-06 Thread Alexander Wallace
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
namefactory/name
   
valueorg.apache.commons.dbcp.BasicDataSourceFactory/value
  /parameter
  parameter
namedriverClassName/name
valueorg.postgresql.Driver/value
  /parameter
  parameter
nameurl/name
   
valuejdbc:postgresql://IP.GOES.HERE.XX/db_name_goes_here/value
  /parameter
  parameter
nameusername/name
valueTheUserNameGoesHere/value
  /parameter
  parameter
namepassword/name
valueThePasswordGoesHere/value
  /parameter
  parameter
namemaxActive/name
value50/value
  /parameter
  parameter
namemaxIdle/name
value10/value
  /parameter
  parameter
namemaxWait/name
value-1/value
  /parameter
/ResourceParams 

then my web.xml

  resource-ref
descriptionpostgreSQL Datasource/description
res-ref-namejdbc/postgresql/res-ref-name
res-typejavax.sql.DataSource/res-type
res-authContainer/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]




Re: connection pool to postgresql

2002-12-06 Thread Craig R. McClanahan


On Fri, 6 Dec 2002, Dionisio Ruiz de Zarate wrote:

 Date: Fri, 6 Dec 2002 23:11:37 +0100
 From: Dionisio Ruiz de Zarate [EMAIL PROTECTED]
 Reply-To: Tomcat Users List [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: connection pool to postgresql

 Hello can anybody help me to configure one connection pool to postgresql
 from tomcat?
 and how can i use fron one java class?
 thanks



Configuration examples are in the docs shipped with Tomcat, or available
online:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

which also includes example code for accessing and using the connection
pool.  Note that the application level code is basically independent of
what actual database you're using under the covers.

Craig



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]