You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Simon Wong <si...@pighome.com> on 2003/02/20 08:38:14 UTC
DB2 version 8.1 using Jakarta Commons Connection Pool
Hello, all,
Does anyone successfully configure DB2 version 8.1 using Jakarta Commons
Connection Pool?
Could you share your experience with us?
Thanks in advance,
Simon
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: DB2 version 8.1 using Jakarta Commons Connection Pool
Posted by Fabio Mengue <fa...@ccuec.unicamp.br>.
Hello,
I don't exactly know the version (or revision) of DB2 we are using, but
it is working.
Configuration:
-DB2 version x.x on Solaris
-Tomcat 4.1.x on Linux with DB2 ClientConnect instaled
- Sun jdk 1.3.x.
Add the following line
JAVA_OPTS="-Djava.library.path=<DB2>/sqllib/java12/"
to file <TOMCAT>/bin/setclasspath.sh.
Create <TOMCAT>/bin/setenv.sh, as a copy (or a link) of file
<DB2>/sqllib/db2profile.
Create <TOMCAT>/common/lib/db2java.jar (has to be a .jar file, the name
don't really matter). This is a copy (or a link) of file
<DB2>/sqllib/java12/db2java.zip.
Added (in the right place, look for a similar entry as example) to
<TOMCAT>/conf/server.xml:
<Context path="/myapp" docBase="myapp" debug="99"
reloadable="true" crossContext="true">
<Resource name="jdbc/db2"
auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/db2">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>COM.ibm.db2.jdbc.app.DB2Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:db2:MYDATABASE</value>
</parameter>
<parameter>
<name>username</name>
<value>myusername</value>
</parameter>
<parameter>
<name>password</name>
<value>mypassword</value>
</parameter>
<parameter>
<name>driverName</name>
<value>jdbc:db2:MYDATABASE</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>0</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
</ResourceParams>
</Context>
Here, myapp is the name of your .war file or directory in
<TOMCAT>/webapps. Of course your directory name will be different.
Add (in the right place, look for a similar entry as example or if the
file is "empty", put it between <web-app> and </web-app>) to
<TOMCAT>/webapps/myapp/WEB-INF/web.xml:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/db2</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
And then, your servlet code may have something like this:
import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
...
Connection c = null;
try {
Context ctx = (Context) new
InitialContext().lookup("java:comp/env");
c = ((DataSource) ctx.lookup("jdbc/db2")).getConnection();
} catch (Exception e) {
e.printStackTrace(System.err);
}
Variable 'c' is now a pooled DB2 connection.
I think that's it. Hope that helps,
Fabio.
Simon Wong wrote:
>Hello, all,
>
>Does anyone successfully configure DB2 version 8.1 using Jakarta Commons
>Connection Pool?
>
>Could you share your experience with us?
>
>
>
>Thanks in advance,
>Simon
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
--
Fabio Mengue - Centro de Computacao - Unicamp
fabio@ccuec.unicamp.br fabio@unicamp.br
----------------------------------------------------------------
Testing can show the presence of bugs, not their absence. Edsger W. Dijkstra
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org