Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

Поиск
Список
Период
Сортировка
Искать

Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

От:
"CRAIG GOLBY" <craig@golby.me.uk>
Дата:
Help, I am tearing my hair out.
 
I am a newbie to Linux and Tomcat, and am therefore amazed that I have got as far as I have, that said I now seem to be stuck in front of a brick wall, with no ladder !!
 
Tomcat 4.1.24 is running on ServerOne (Red Hat 9), it is currently serving out a couple of very basic JSP's and seems to be working quite well. ServerOne also has J2SDK 1.4.1_03 installed.  PostgreSQL 7.3 is running on ServerTwo (Red Hat 9).  Have also installed pgAdminIII on both a Windows Laptop and ServerTwo.  The Laptop version works fine, if a little unstable, so TCP/IP connectivity is working fine.
 
Within PostgreSQL I have created a new Db called "PersonalDb", within the public Schema I have created a table called "testOne".  TestOne has three columns, Id, FieldOne and DateStamp, and there are currently 2 rows of data within the table
 
Sample of code used is below, along with a list of the Jar files in common/lib.
 
I have read through so many mailing lists now and tried so many things that I dont know what I have and havent done, am fairly sure that it is either a configuration issue or a missing file so will no doubt kick myself when I find out the answer.
 
Any assistance would be greatly appreciated.
 
Regards
 
 
Craig
 
 
*******************************************************
Server XML :- Tomcat/conf
*******************************************************
<Context path="/DBTest"
         docBase="DBTest"
         debug="5"
         reloadable="true"
         crossContext="true">
 
<Logger className="org.apache.catalina.logger.FileLogger"
        prefix="localhost_DBTest_log." suffix=".txt"
        timestamp="true"/>
 
<Resource name="jdbc/PersonalDb"
          type="javax.sql.DataSource"
          auth="Container"/>
 
<ResourceParams name="jdbc/PersonalDb">
 <parameter>
  <name>factory</name>
  <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
 </parameter>
 
 <parameter>
  <name>driverClassName</name>
  <value>org.postgresql.Driver</value>
 </parameter>
 
 <parameter>
  <name>url</name>
  <value>jdbc:postgresql://ServerTwo:5432/PersonalDb</value>
 </parameter>
 
 <parameter>
  <name>username</name>
  <value>myUser</value>
 </parameter>
 
 <parameter>
  <name>password</name>
  <value>myPassword</value>
 </parameter>
 
 <parameter>
  <name>maxActive</name>
  <value>10</value>
 </parameter>
 
 <parameter>
  <name>maxIdle</name>
  <value>30</value>
 </parameter>
 
 <parameter>
  <name>maxWait</name>
  <value>10000</value>
 </parameter>
 
</ResourceParams>
</Context>
 
</Host>
</Engine>
</Service>
 
 
*******************************************************
Web XML  :-  Tomcat/webapps/root/WEB-INF
*******************************************************
  <description>PostgreSQL Test App</description>
    <resource-ref>
       <description>postgreSQL Datasource example</description>
       <res-ref-name>jdbc/PersonalDb</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
 
 
*******************************************************
My Class File
*******************************************************
 
  public void init() {
    try{
      Context ctx = new InitialContext();
      if(ctx == null )
          throw new Exception("Boom - No Context");
      status = "checking CTX";
 
      DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");
      status = "Completing Lookup of CTX";
     
      if (ds != null)
        {
         status = "Creating Connection";
         Connection conn = ds.getConnection();   <----- FAILS HERE
         status = "Created Connection";
         if(conn != null) 
           {
            foo = "Got Connection "+conn.toString();
            Statement stmt = conn.createStatement();
            ResultSet rst =
                stmt.executeQuery(
                  "select Id, FieldOne, DateStamp from Public.testOne");
            status = "Completing Select";
            if(rst.next())
            {
               foo=rst.getString(2);
               bar=rst.getInt(3);
            }
            status = "Looped through Resultset";           
            conn.close();
           }
        }
      else {status = "Fell into Else";} 
    }catch(Exception e) {
      e.printStackTrace();
        status = status + ", now in exception block :-" + e.toString();
 
    }
 }
*******************************************************
Class Files in Tomcat/common/lib
*******************************************************
activation.jar
ant.jar
collections-2.1.jar
commons-collections.jar
commons-dbcp-1.0.jar
commons-dbcp.jar
commons-logging-api.jar
commons-pool.jar
jasper-compiler.jar
jasper-runtime.jar
jdbc2_0-stdext.jar
jndi.jar
jta.jar
mail.jar
naming-common.jar
naming-factory.jar
naming-resources.jar
pg73jdbc3.jar
pool-1.0.1.jar
postgresql.jar    (Copy of  pg73jdbc3.jar)
servlet.jar
 
 
 
 
 

Re: Tomcat - PostgreSQL - Cannot load JDBC driver class

От:
Dave Cramer <Dave@micro-automation.net>
Дата:
Craig,

So what happens, does it fail, does it run, does it throw an exeption?

Dave
On Fri, 2003-09-26 at 12:29, CRAIG GOLBY wrote:
> Help, I am tearing my hair out.
>  
> I am a newbie to Linux and Tomcat, and am therefore amazed that I have
> got as far as I have, that said I now seem to be stuck in front of a
> brick wall, with no ladder !!
>  
> Tomcat 4.1.24 is running on ServerOne (Red Hat 9), it is currently
> serving out a couple of very basic JSP's and seems to be working quite
> well. ServerOne also has J2SDK 1.4.1_03 installed.  PostgreSQL 7.3 is
> running on ServerTwo (Red Hat 9).  Have also installed pgAdminIII on
> both a Windows Laptop and ServerTwo.  The Laptop version works fine,
> if a little unstable, so TCP/IP connectivity is working fine.
>  
> Within PostgreSQL I have created a new Db called "PersonalDb", within
> the public Schema I have created a table called "testOne".  TestOne
> has three columns, Id, FieldOne and DateStamp, and there are currently
> 2 rows of data within the table
>  
> Sample of code used is below, along with a list of the Jar files in
> common/lib.
>  
> I have read through so many mailing lists now and tried so many things
> that I dont know what I have and havent done, am fairly sure that it
> is either a configuration issue or a missing file so will no doubt
> kick myself when I find out the answer.
>  
> Any assistance would be greatly appreciated.
>  
> Regards
>  
>  
> Craig
>  
>  
> *******************************************************
> Server XML :- Tomcat/conf
> *******************************************************
>           docBase="DBTest"
>          debug="5" 
>          reloadable="true" 
>          crossContext="true">
>  
>          prefix="localhost_DBTest_log." suffix=".txt"
>         timestamp="true"/>
>  
>            type="javax.sql.DataSource"
>           auth="Container"/> 
>  
> 
>  
>   factory
>   org.apache.commons.dbcp.BasicDataSourceFactory
>  
>  
>  
>   driverClassName
>   org.postgresql.Driver
>  
>  
>  
>   url
>   jdbc:postgresql://ServerTwo:5432/PersonalDb
>  
>  
>  
>   username
>   myUser
>  
>  
>  
>   password
>   myPassword
>  
>  
>  
>   maxActive
>   10
>  
>  
>  
>   maxIdle
>   30
>  
>  
>  
>   maxWait
>   10000
>  
>  
>  
> 
>  
> 
> 
> 
>  
>  
> *******************************************************
> Web XML  :-  Tomcat/webapps/root/WEB-INF
> *******************************************************
>   PostgreSQL Test App
>     
>        postgreSQL Datasource example
>        jdbc/PersonalDb
>        javax.sql.DataSource
>        Container
>    
> 
>  
>  
> *******************************************************
> My Class File
> *******************************************************
>  
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null ) 
>           throw new Exception("Boom - No Context");
>       status = "checking CTX";
>  
>       DataSource ds =
> (DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");
>       status = "Completing Lookup of CTX";
>       
>       if (ds != null) 
>         {
>          status = "Creating Connection";
>          Connection conn = ds.getConnection();   <----- FAILS HERE
>          status = "Created Connection";
>          if(conn != null)  
>            {
>             foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst = 
>                 stmt.executeQuery(
>                   "select Id, FieldOne, DateStamp from
> Public.testOne");
>             status = "Completing Select";
>             if(rst.next()) 
>             {
>                foo=rst.getString(2);
>                bar=rst.getInt(3);
>             }
>             status = "Looped through Resultset";            
>             conn.close();
>            }
>         }
>       else {status = "Fell into Else";}  
>     }catch(Exception e) {
>       e.printStackTrace();
>         status = status + ", now in exception block :-" +
> e.toString();
>  
>     }
>  }
> 
> *******************************************************
> Class Files in Tomcat/common/lib
> *******************************************************
> activation.jar
> ant.jar
> collections-2.1.jar
> commons-collections.jar
> commons-dbcp-1.0.jar
> commons-dbcp.jar
> commons-logging-api.jar
> commons-pool.jar
> jasper-compiler.jar
> jasper-runtime.jar
> jdbc2_0-stdext.jar
> jndi.jar
> jta.jar
> mail.jar
> naming-common.jar
> naming-factory.jar
> naming-resources.jar
> pg73jdbc3.jar
> pool-1.0.1.jar
> postgresql.jar    (Copy of  pg73jdbc3.jar)
> servlet.jar
>  
>  
>  
>  
>  
-- 
Dave Cramer 

Re: Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

От:
Ron <rstpierre@syscor.com>
Дата:
You've probably checked this, but on the offchance you haven't, are you 
explicitly pointing to the postgres jdbc jar file in your classpath?
eg 
CLASSPATH=$CLASSPATH:.:...whatever...:/usr/local/Tomcat/common/lib/pg73jdbc3.jar

Ron

CRAIG GOLBY wrote:

> Help, I am tearing my hair out.
>  
> I am a newbie to Linux and Tomcat, and am therefore amazed that I have 
> got as far as I have, that said I now seem to be stuck in front of a 
> brick wall, with no ladder !!
>  
> Tomcat 4.1.24 is running on ServerOne (Red Hat 9), it is currently 
> serving out a couple of very basic JSP's and seems to be working quite 
> well. ServerOne also has J2SDK 1.4.1_03 installed.  PostgreSQL 7.3 is 
> running on ServerTwo (Red Hat 9).  Have also installed pgAdminIII on 
> both a Windows Laptop and ServerTwo.  The Laptop version works fine, 
> if a little unstable, so TCP/IP connectivity is working fine.
>  
> Within PostgreSQL I have created a new Db called "PersonalDb", within 
> the public Schema I have created a table called "testOne".  TestOne 
> has three columns, Id, FieldOne and DateStamp, and there are currently 
> 2 rows of data within the table
>  
> Sample of code used is below, along with a list of the Jar files in 
> common/lib.
>  
> I have read through so many mailing lists now and tried so many things 
> that I dont know what I have and havent done, am fairly sure that it 
> is either a configuration issue or a missing file so will no doubt 
> kick myself when I find out the answer.
>  
> Any assistance would be greatly appreciated.
>  
> Regards
>  
>  
> Craig
>  
>  
> *******************************************************
> Server XML :- Tomcat/conf
> *******************************************************
>           docBase="DBTest"
>          debug="5"
>          reloadable="true"
>          crossContext="true">
>  
>          prefix="localhost_DBTest_log." suffix=".txt"
>         timestamp="true"/>
>  
>            type="javax.sql.DataSource"
>           auth="Container"/>
>  
> 
>  
>   factory
>   org.apache.commons.dbcp.BasicDataSourceFactory
>  
>  
>  
>   driverClassName
>   org.postgresql.Driver
>  
>  
>  
>   url
>   jdbc:postgresql://ServerTwo:5432/PersonalDb
>  
>  
>  
>   username
>   myUser
>  
>  
>  
>   password
>   myPassword
>  
>  
>  
>   maxActive
>   10
>  
>  
>  
>   maxIdle
>   30
>  
>  
>  
>   maxWait
>   10000
>  
>  
> 
> 
>  
> 
> 
> 
>  
>  
> *******************************************************
> Web XML  :-  Tomcat/webapps/root/WEB-INF
> *******************************************************
>   PostgreSQL Test App
>     
>        postgreSQL Datasource example
>        jdbc/PersonalDb
>        javax.sql.DataSource
>        Container
>    
>  
>  
> *******************************************************
> My Class File
> *******************************************************
>  
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null )
>           throw new Exception("Boom - No Context");
>       status = "checking CTX";
>  
>       DataSource ds = 
> (DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");
>       status = "Completing Lookup of CTX";
>      
>       if (ds != null)
>         {
>          status = "Creating Connection";
>          Connection conn = ds.getConnection();   <----- FAILS HERE
>          status = "Created Connection";
>          if(conn != null) 
>            {
>             foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst =
>                 stmt.executeQuery(
>                   "select Id, FieldOne, DateStamp from Public.testOne");
>             status = "Completing Select";
>             if(rst.next())
>             {
>                foo=rst.getString(2);
>                bar=rst.getInt(3);
>             }
>             status = "Looped through Resultset";           
>             conn.close();
>            }
>         }
>       else {status = "Fell into Else";} 
>     }catch(Exception e) {
>       e.printStackTrace();
>         status = status + ", now in exception block :-" + e.toString();
>  
>     }
>  }
> *******************************************************
> Class Files in Tomcat/common/lib
> *******************************************************
> activation.jar
> ant.jar
> collections-2.1.jar
> commons-collections.jar
> commons-dbcp-1.0.jar
> commons-dbcp.jar
> commons-logging-api.jar
> commons-pool.jar
> jasper-compiler.jar
> jasper-runtime.jar
> jdbc2_0-stdext.jar
> jndi.jar
> jta.jar
> mail.jar
> naming-common.jar
> naming-factory.jar
> naming-resources.jar
> pg73jdbc3.jar
> pool-1.0.1.jar
> postgresql.jar    (Copy of  pg73jdbc3.jar)
> servlet.jar
>  
>  
>  
>  
>  



Re: Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

От:
"CRAIG GOLBY" <craig@golby.me.uk>
Дата:
I hadnt, but I have now.

The command used was 

CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar:/usr/src/Java/j2sdk1.4.1_0
3/lib/tools.jar:/usr/local/tomcat/common/lib/servlet.jar:/usr/local/tomc
at/common/lib/pg73jdbc3.jar

Which resulted in

.
.
CATALINA_HOME=/usr/local/tomcat
CLASSPATH=/usr/local/tomcat/bin/bootstrap.jar:/usr/src/Java/j2sdk1.4.1_0
3/lib/tools.jar:/usr/local/tomcat/common/lib/servlet.jar:/usr/local/tomc
at/common/lib/pg73jdbc3.jar
COLORS=/etc/DIR_COLORS.xterm
.
.

Unfortunately it made no difference to the problem 

Thanks anyway


-----Original Message-----
From: Ron [mailto:rstpierre@syscor.com] 
Sent: 26 September 2003 18:36
Cc: CRAIG GOLBY; pgsql-jdbc

You've probably checked this, but on the offchance you haven't, are you
explicitly pointing to the postgres jdbc jar file in your classpath?
eg
CLASSPATH=$CLASSPATH:.:...whatever...:/usr/local/Tomcat/common/lib/pg73j
dbc3.jar

Ron

CRAIG GOLBY wrote:

> Help, I am tearing my hair out.
>  
> I am a newbie to Linux and Tomcat, and am therefore amazed that I have

> got as far as I have, that said I now seem to be stuck in front of a 
> brick wall, with no ladder !!
>  
> Tomcat 4.1.24 is running on ServerOne (Red Hat 9), it is currently 
> serving out a couple of very basic JSP's and seems to be working quite

> well. ServerOne also has J2SDK 1.4.1_03 installed.  PostgreSQL 7.3 is 
> running on ServerTwo (Red Hat 9).  Have also installed pgAdminIII on 
> both a Windows Laptop and ServerTwo.  The Laptop version works fine, 
> if a little unstable, so TCP/IP connectivity is working fine.
>  
> Within PostgreSQL I have created a new Db called "PersonalDb", within 
> the public Schema I have created a table called "testOne".  TestOne 
> has three columns, Id, FieldOne and DateStamp, and there are currently
> 2 rows of data within the table
>  
> Sample of code used is below, along with a list of the Jar files in 
> common/lib.
>  
> I have read through so many mailing lists now and tried so many things

> that I dont know what I have and havent done, am fairly sure that it 
> is either a configuration issue or a missing file so will no doubt 
> kick myself when I find out the answer.
>  
> Any assistance would be greatly appreciated.
>  
> Regards
>  
>  
> Craig
>  
>  
> *******************************************************
> Server XML :- Tomcat/conf
> *******************************************************
>           docBase="DBTest"
>          debug="5"
>          reloadable="true"
>          crossContext="true">
>  
>          prefix="localhost_DBTest_log." suffix=".txt"
>         timestamp="true"/>
>  
>            type="javax.sql.DataSource"
>           auth="Container"/>
>  
>   
>   factory
>   org.apache.commons.dbcp.BasicDataSourceFactory
>  
>  
>  
>   driverClassName
>   org.postgresql.Driver
>  
>  
>  
>   url
>   jdbc:postgresql://ServerTwo:5432/PersonalDb
>  
>  
>  
>   username
>   myUser
>  
>  
>  
>   password
>   myPassword
>  
>  
>  
>   maxActive
>   10
>  
>  
>  
>   maxIdle
>   30
>  
>  
>  
>   maxWait
>   10000
>  
>  
> 
> 
>  
> 
> 
> 
>  
>  
> *******************************************************
> Web XML  :-  Tomcat/webapps/root/WEB-INF
> *******************************************************
>   PostgreSQL Test App
>     
>        postgreSQL Datasource example
>        jdbc/PersonalDb
>        javax.sql.DataSource
>        Container
>    
>  
>  
> *******************************************************
> My Class File
> *******************************************************
>  
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null )
>           throw new Exception("Boom - No Context");
>       status = "checking CTX";
>  
>       DataSource ds =
> (DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");
>       status = "Completing Lookup of CTX";
>      
>       if (ds != null)
>         {
>          status = "Creating Connection";
>          Connection conn = ds.getConnection();   <----- FAILS HERE
>          status = "Created Connection";
>          if(conn != null) 
>            {
>             foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst =
>                 stmt.executeQuery(
>                   "select Id, FieldOne, DateStamp from
Public.testOne");
>             status = "Completing Select";
>             if(rst.next())
>             {
>                foo=rst.getString(2);
>                bar=rst.getInt(3);
>             }
>             status = "Looped through Resultset";           
>             conn.close();
>            }
>         }
>       else {status = "Fell into Else";} 
>     }catch(Exception e) {
>       e.printStackTrace();
>         status = status + ", now in exception block :-" + 
> e.toString();
>  
>     }
>  }
> *******************************************************
> Class Files in Tomcat/common/lib
> *******************************************************
> activation.jar
> ant.jar
> collections-2.1.jar
> commons-collections.jar
> commons-dbcp-1.0.jar
> commons-dbcp.jar
> commons-logging-api.jar
> commons-pool.jar
> jasper-compiler.jar
> jasper-runtime.jar
> jdbc2_0-stdext.jar
> jndi.jar
> jta.jar
> mail.jar
> naming-common.jar
> naming-factory.jar
> naming-resources.jar
> pg73jdbc3.jar
> pool-1.0.1.jar
> postgresql.jar    (Copy of  pg73jdbc3.jar)
> servlet.jar
>  
>  
>  
>  
>  





Re: Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

От:
Paul Thomas <paul@tmsl.demon.co.uk>
Дата:

On 26/09/2003 17:29 CRAIG GOLBY wrote:
> [snip]
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null )
>           throw new Exception("Boom - No Context");
>       status = "checking CTX";
> 
>       DataSource ds =
> (DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");
>       status = "Completing Lookup of CTX";
> 
>       if (ds != null)
>         {
>          status = "Creating Connection";
>          Connection conn = ds.getConnection();   <----- FAILS HERE

With a NullPointerException I presume? Try

       DataSource ds = 
(DataSource)ctx.lookupLink("java:comp/env/jdbc/PersonalDb");

And rememeber that the JDBC driver _must_ be in common/lib and _must not_ 
be in the classpath.

HTH

-- 
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller 
Business |
| Computer Consultants         | 
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: Tomcat - PostgreSQL - Cannot load JDBC driver class "null"

От:
Paul Thomas <paul@tmsl.demon.co.uk>
Дата:

On 27/09/2003 10:23 Paul Thomas wrote:
> 
> With a NullPointerException I presume? Try
> 
>       DataSource ds = 
> (DataSource)ctx.lookupLink("java:comp/env/jdbc/PersonalDb");
> 
> And rememeber that the JDBC driver _must_ be in common/lib and _must 
> not_ be in the classpath.

Whoops! Actually looking at source code instead relying on memory, that 
should be something like

        InitialContext cxt = new InitialContext();
        Context ctx2 = (Context)ctx.lookup("java:comp/env");
        DataSource ds = (DataSource)ctx2.lookupLink("jdbc/PersonalDb");

Which is the only way I could find which worked on Tomcat 4.1.12. I've 
just retried this on 4.1.24

        InitialContext cxt = new InitialContext();
        DataSource ds = 
(DataSource)ctx.lookup("java:comp/env/jdbc/PersonalDb");

and that works too so whatever the problem was on the older version seems 
to have been fixed.

-- 
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller 
Business |
| Computer Consultants         | 
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+
FAQ