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]