You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul <pa...@msci.ca> on 2003/09/02 17:40:40 UTC
Re: dbcp config problems
thanks, i appreciate the response. I checked out the reference you
supplied. Started following it and realized that the commons-dbcp and -pool
packages needed to be unzipped first - that the jar files were contained
inside. Everything else worked once the proper packages were put in place.
-pl
----- Original Message -----
From: <ke...@new-era-of-networks.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Friday, August 29, 2003 2:15 PM
Subject: Re: dbcp config problems
>
> If you're getting "
>
> javax.naming.NamingException: Cannot create resource instance" then you
> need to install the commons-pool and commons-dbcp jars. These jars
aren't
> part of the standard distribution you have. Here's a link to an article
I
> used to figure out this problem:
> http://www.developer.com/java/data/print.php/10932_2172891_3
>
> It contains links to download both jars.
>
>
>
> If this isn't your problem, then post the stack trace.
>
>
>
> "Paul"
> <pa...@msci.ca> To: "Tomcat Users
List" <to...@jakarta.apache.org>
> cc:
> 08/29/2003 12:05 Subject: dbcp config
problems
> PM
> Please respond to
> "Tomcat Users
> List"
>
>
>
>
>
> Based on Tomcat41 docs, jndi-datasource-examples-howto.html, have tried to
> setup a database connection pool as follows, but get result:
>
> Foo Not Connected
> Bar -1
>
> generated from following jsp code, as per howto given above:
>
> <%
> foo.DBTest tst = new foo.DBTest();
> tst.init();
> %>
> <%= tst.getFoo() %>
> <%= tst.getBar() %>
>
> Not sure what i am doing wrong. If anyone has any ideas, or suggestioins
> as to how to go about trouble-shooting, please let me know (see below for
> config info used).
> -thanks, paul.
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> software system:
>
> win2k
> java jdk 1.4
> jakarta-tomcat-4.1.27-LE-jdk14.exe
> apache_2.0.47-win32-x86-no_ssl.msi
> jk2 connector
>
> %CATALINA_HOME%\common\lib:
>
> commons-collections-2.1.jar
> commons-dbcp-1.0.jar
> commons-pool-1.0.1.jar
> plus: oracle jdbc driver 9.x with .jar extension
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> %CATALINA_HOME%\conf\server.xml:
>
> <!-- Add btween </Context> of examples context & </Host> closing localhost
> definition -->
> <Context path="/epl" docBase="epl" debug="5" reloadable="true"
> crossContext="true">
>
> <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="localhost_DBTest_log." suffix=".txt" timestamp="true"/>
>
> <!-- Define a Datasource -->
> <Resource name="jdbc/eplResrc" auth="Container"
> type="javax.sql.DataSource"/>
>
> <ResourceParams name="jdbc/eplResrc">
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
>
> <parameter>
> <name>factory</name>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> </parameter>
>
> <!-- Maximum number of dB connections in pool. Set to 0 for no limit
> -->
> <parameter>
> <name>maxActive</name>
> <value>10</value>
> </parameter>
>
> <parameter>
> <name>maxIdle</name>
> <value>10</value>
> </parameter>
>
> <!-- Maximum time to wait for a dB connection to become available
> in ms, in this example 10 seconds. An Exception is thrown if this
> timeout is exceeded. Set to -1 to wait indefinitely. -->
> <parameter>
> <name>maxWait</name>
> <value>10000</value>
> </parameter>
>
> <parameter>
> <name>username</name>
> <value>scott</value>
> </parameter>
>
> <parameter>
> <name>password</name>
> <value>tiger</value>
> </parameter>
>
> <parameter>
> <name>driverClassName</name>
> <value>oracle.jdbc.driver.OracleDriver</value>
> </parameter>
>
> <parameter>
> <name>url</name>
> <value>jdbc:oracle:thin:@pl-wkstn:1521:www</value>
> </parameter>
>
> <!-- To configure a DBCP DataSource, abandoned dB connections are
removed
> and recycled -->
> <parameter>
> <name>removeAbandoned</name>
> <value>true</value>
> </parameter>
>
> <!-- number of seconds a dB connection has been idle before it is
> considered abandoned -->
> <parameter>
> <name>removeAbandonedTimeout</name>
> <value>60</value>
> </parameter>
>
>
> </ResourceParams>
> </Context>
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>
> %WEB-INF\web.xml
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app PUBLIC
> "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
> <description>db Test App</description>
> <resource-ref>
> <description>DB Connection</description>
> <res-ref-name>jdbc/eplResrc</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
> </web-app>
>
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> %WEB-INF%\classes\foo\DBTest.java
>
> package foo;
>
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
>
> public class DBTest {
>
> String foo = "Not Connected";
> int bar = -1;
>
> public void init() {
> try{
> if(ctx == null )
> throw new Exception("Boom - No Context");
>
> DataSource ds =
> (DataSource)ctx.lookup(
> java:comp/env/jdbc/eplResrc");
>
> if (ds != null) {
> Connection conn = ds.getConnection();
>
> if(conn != null) {
> foo = "Got Connection "+conn.toString();
> Statement stmt = conn.createStatement();
> ResultSet rst =
> stmt.executeQuery("select sysdate from dual");
> if(rst.next()) {
> foo=rst.getString(2);
> bar=rst.getInt(3);
> }
> conn.close();
> }
> }
> }catch(Exception e) {
> e.printStackTrace();
> }
> }
>
> public String getFoo() { return foo; }
> public int getBar() { return bar;}
> }
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>