the docBase attribute of the <Context> element in server.xml must point to
the fully qualified path of the web app from which you will be referencing
this data source. An incorrect path will result in the SQL exception in the
subject.

Case closed.

On 8/3/06, Roy Kiesler <[EMAIL PROTECTED]> wrote:

I have been trying for 2 days now to setup a simple connection pool in
Tomcat 4.0.6 for a Hypersonic database with the ever-so-popular error in
the subject. I have read every possible Google post on the subject, but
found not solution for Tomcat 4, only 5.x.

Anyhow, here's the setup:


   1. hsqldb.jar is placed in %CATALINA_HOME%/common/lib
   2. %CATALINA_HOME%/server/conf/server.xml contains the following
   context definition:

   <Context path="/BookmartDB"
            docBase="BookmartDB"
            debug="5"
            reloadable="true"
            crossContext="true">

      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="localhost_BookmartDB_log."
              suffix=".txt"
              timestamp="true"/>

      <Resource name="jdbc/BookmartDB"
                auth="Container"
                type="javax.sql.DataSource"/>

      <ResourceParams name="jdbc/BookmartDB">
         <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
         </parameter>

         <parameter>
            <name>maxActive</name>
            <value>100</value>
         </parameter>

         <parameter>
            <name>maxIdle</name>
            <value>30</value>
         </parameter>

         <parameter>
            <name>maxWait</name>
            <value>10000</value>
         </parameter>

         <parameter>
            <name>username</name>
            <value>sa</value>
         </parameter>

         <parameter>
            <name>password</name>
            <value></value>
         </parameter>

         <parameter>
            <name>driverClassName</name>
            <value>org.hsqldb.jdbcDriver</value>
         </parameter>

         <parameter>
            <name>url</name>
            <value>jdbc:hsqldb:file:c:/bookmart</value>
         </parameter>

         <parameter>
            <name>removeAbandoned</name>
            <value>true</value>
         </parameter>

         <parameter>
            <name>removeAbandonedTimeout</name>
            <value>60</value>
         </parameter>

         <parameter>
            <name>logAbandoned</name>
            <value>true</value>
         </parameter>

      </ResourceParams>
   </Context>

   3. %CATALINA_HOME%/server/webapps/bookmartClient/WEB-INF/web.xml
   contains the following resource reference:

   <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/BookmartDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
   </resource-ref>

   4. My JSP code contains the following:

   Context initCtx = new InitialContext();
   Context envCtx = (Context) initCtx.lookup("java:comp/env");
   DataSource ds = (DataSource)envCtx.lookup("jdbc/BookmartDB");
   Connection conn = ds.getConnection();

This does not appear to be an issue with the driver, as the following code
works just fine:

Class.forName("org.hsqldb.jdbcDriver" );
Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:c:/bookmart",
"sa", "");
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select * from testdata");
if (rst.next())
{
   foo = rst.getString(2);
   bar = rst.getInt(3);
}

Hopefully this paints the picture clearly enough. Any insights?

Thanks,
--
Roy




--
Roy Kiesler | [EMAIL PROTECTED] | f: 801-439-4051 | m: 925-876-6323

Reply via email to