Hi,

I am using Tomcat 4.1.12 and trying to use the JNDI service to get a
database connection.

My code looks like this:
      Context ctx = new InitialContext();
      Object o = ctx.lookup("java:comp/env/jdbc/WebsydianTest");
      DataSource ds = (DataSource) o;
      Connection conn = ds.getConnection();

The last statement results in the following exception:
java.sql.SQLException: Cannot load JDBC driver class 'null'

Having debugged a little bit I have found out that it seems that the
returned DataSource object is not initialized with any of the parameters in
the server.xml file. I used the following code to verify this:
     org.apache.commons.dbcp.BasicDataSource bds =
                (org.apache.commons.dbcp.BasicDataSource) ds;
     out.println("<p>Max active: " + bds.getMaxActive() + "</p>");
     out.println("<p>Max idle: " + bds.getMaxIdle() + "</p>");
     out.println("<p>Max wait: " + bds.getMaxWait() + "</p>");
     out.println("<p>User: " + bds.getUsername() + "</p>");
     out.println("<p>Password: " + bds.getPassword() + "</p>");

What am I doing wrong? I have searched the archive and I can see that I am
not the only one getting this error message, but none of the solutions seems
to have something to do with that the parameters are not loaded from the
server.xml file.

My server.xml file looks like this:
<Server className="org.apache.catalina.core.StandardServer" debug="0"
port="8005" shutdown="SHUTDOWN">
...
  <GlobalNamingResources>
...
    <Resource auth="Container" name="jdbc/WebsydianTest"
type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/WebsydianTest">
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>sun.jdbc.odbc.JdbcOdbcDriver</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:odbc:Websydiantest</value>
      </parameter>
      <parameter>
        <name>validationQuery</name>
        <value>select * from AA1T</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>user</name>
        <value>dba</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>dba</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>sql</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
...
</server>


My web-inf/web.xml file looks like this:
<web-app>
...
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/WebsydianTest</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

Any help will be appreciated.
Ulrik

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

Reply via email to