Thread: Re: Tomcat - PostgreSQL - Cannot load JDBC driverclass"null"

Re: Tomcat - PostgreSQL - Cannot load JDBC driverclass"null"

From
"CRAIG GOLBY"
Date:
There are a number of other dirs under WebApps, those being "examples",
"tomcat-docs" and "webdav", plus a few backups or ROOT that I have
created at different stages of the build.

There is also an admin.xml and manager.xml file in the webapps
directory, both have small amounts of information in them, not sure that
they have any bearing.

Have just spent a few minutes through the jar files that are in
common/lib and comparing them with what the various xml files suggested
were needed. I managed to locate a jar file containing the appropriate
class in every instance, bar one, the file logger.

org.apache.catalina.logger.FileLogger

javax.sql.DataSource
/usr/local/jakarta-tomcat-4.1.24/common/jdbc2_0-stdext.jar

org.apache.commons.dbcp.BasicDataSourceFactory
/usr/local/jakarta-tomcat-4.1.24/common/commons-dbcp.jar

org.postgresql.Driver
/usr/local/jakarta-tomcat-4.1.24/common/pg73jdbc3.jar

I know that I was clutching at straws, and the exception does seem to
talk about the driver, however I commented out this section of the
server.xml and then restarted tomcat, sadly, but not suprisingly there
was no difference in the result.

I am stopping for the evening now, before the wife kills me, but if you
have any other suggestions then please do let me know.

Thanks for your help so far

Regards



Craig


-----Original Message-----
From: Dave Cramer [mailto:Dave@micro-automation.net]
Sent: 26 September 2003 20:20
To: CRAIG GOLBY


What context are you using for your webapp?

is there another dir under webapps/ besides ROOT

Dave
On Fri, 2003-09-26 at 14:48, CRAIG GOLBY wrote:
> Okay will have a look for some documentation.
>
> When I indicated it was in ROOT, I didn't mean the operating system
> root, but the ROOT directory that Tomcat seems to set up as the
> default location for its webapps, hence ...
>
> Tomcat/webapps/ROOT/WEB-INF/lib
>
> As I am learning as I go along I am trying to stick to as many
> defaults as I can, I will then look to start again in a more logical
> location, and build that up with what I have learnt here.
>
> If that is the case, have I put the jar in the right WEB-INF/lib  ?
>
>
> -----Original Message-----
> From: Dave Cramer [mailto:Dave@micro-automation.net]
> Sent: 26 September 2003 19:41
> To: CRAIG GOLBY
>
> Craig,
>
> Ok, you probably should read the bit on class loading for webapps, it
> is rather complicated.
>
> Anyways, it needs to go into the WEB-INF/lib of the context you are
> using which is probably not ROOT
>
> Dave
> On Fri, 2003-09-26 at 14:27, CRAIG GOLBY wrote:
> > Be as Obtuse as you want Dave :-}}
> >
> > I was having a stupid moment and realised what I had done as soon as

> > I
>
> > sent the mail.
> >
> > As your mail arrived back, I had just stopped and started Tomcat
> > having placed pg73jdbc3.jar into Tomcat/webapps/ROOT/WEB-INF/lib
> >
> > Still no better though.
> >
> > Is this exception indicating something as simple as a file that is
> > missing, or is it a fundamental failure in my code ??
> >
> > Regards
> >
> >
> > Craig
> >
> >
> > -----Original Message-----
> > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > Sent: 26 September 2003 19:21
> > To: CRAIG GOLBY
> >
> > Craig,
> >
> > Sorry for being obtuse, you just need to put the jar in lib dir, not

> > the class
> >
> > Dave
> > On Fri, 2003-09-26 at 14:15, CRAIG GOLBY wrote:
> > > Thanks Dave,
> > >
> > > Have extracted org.postgresql.Driver and put it under WEB-INF,
> > > creating a structure of
> > > Tomcat/webapps/ROOT/WEB-INF/lib/org/postgresql/Driver.class, made
> > > no
>
> > > difference.
> > >
> > > On suggestion 2, I don't appear to have a jre/lib/ext from root or

> > > anywhere in the Tomcat structure, am I missing something here ??
> > >
> > > Suggestion 3, would love to, but havent written any servlets
> > > before so
> >
> > > will need to get the book out.  Will let you know.
> > >
> > >
> > > -----Original Message-----
> > > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > > Sent: 26 September 2003 18:24
> > > To: CRAIG GOLBY
> > >
> > > Craig,
> > >
> > > Ok, couple of things you can try. I seem to remember it not
> > > working in
> >
> > > common/lib, but then I've also given up on tomcat.
> > >
> > > 1) move the driver into the WEB-INF/lib dir
> > > 2) move the driver into the jre/lib/ext dir    this is real
overkill
> > > 3) try writing a very small servlet that just loads the driver,
> > > remember you have to set autoload or whatever in the web.xml file
> > > for this servlet.
> > >
> > > ie
> > >
> > > class servletclass
> > > {
> > >     init(....)
> > >
> > >     load postgres
> > >
> > > }
> > >
> > >
> > > Cheers,
> > >
> > > Dave
> > >
> > > On Fri, 2003-09-26 at 13:09, CRAIG GOLBY wrote:
> > > > Sorry, bound to miss the obvious, it throws an Exception:-
> > > >
> > > > java.sql.SQLException: Cannot load JDBC driver class 'null'
> > > >
> > > > -----Original Message-----
> > > > From: Dave Cramer [mailto:Dave@micro-automation.net]
> > > > Sent: 26 September 2003 18:03
> > > > To: CRAIG GOLBY
> > > > Cc: pgsql-jdbc@postgresql.org
> > > >
> > > > 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
> > > > > *******************************************************
> > > > > <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
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > --
> > > > Dave Cramer <Dave@micro-automation.net>
> > > >
> > > >
> > > >
> > > --
> > > Dave Cramer <Dave@micro-automation.net>
> > >
> > >
> > >
> > --
> > Dave Cramer <Dave@micro-automation.net>
> >
> >
> >
> --
> Dave Cramer <Dave@micro-automation.net>
>
>
>
--
Dave Cramer <Dave@micro-automation.net>




Re: Tomcat - PostgreSQL - Cannot load JDBC driverclass"null"

From
Jim Wright
Date:
Hi Craig,

CRAIG GOLBY wrote:

 >There are a number of other dirs under WebApps, those being "examples",
 >"tomcat-docs" and "webdav", plus a few backups or ROOT that I have
 >created at different stages of the build.
 >
 >There is also an admin.xml and manager.xml file in the webapps
 >directory, both have small amounts of information in them, not sure that
 >they have any bearing.

You can either define web apps in server.xml or in files like these.
You may well find these two useful in your current situation.

Manager is for stopping, starting, restarting webapps and helps
if you are making changes.

Administrator allows you to set up datasources which is cool but
strikes me as ambitious until you have got it working with:

Connection db = DriverManager.getConnection(
     "jdbc:postgresql://host:port/database", username, password);

Anyway, by default the ROOT web app just displays the tomcat test page
which has links to the admin and manager web apps.

If you don't have the tomcat test page (e.g. because you have
broken the default config ;-)) then for tomcat 4 on RH 8.0 the
above are at:

http://localhost:8080/manager/html
http://localhost:8080/admin

until you break that too ;-)

You will be asked to log in as a user defined in
Tomcat/conf/tomcat-users.xml e.g.:

<user username="admin" password="4gotenit" fullName="Adminstrator" roles="admin,manager"/>

 >>>>>>*******************************************************
 >>>>>>Server XML :- Tomcat/conf
 >>>>>>*******************************************************
 >>>>>><Context path="/DBTest"
 >>>>>>         docBase="DBTest"
 >>>>>>         debug="5"
 >>>>>>         reloadable="true"
 >>>>>>         crossContext="true">

I think this means that your web app is installed at Tomcat/webapps/DBTest
assuming you have:

<Host name="localhost" debug="0" appBase="webapps" ...

earlier in the file.

 >>>>>>
 >>>>>>*******************************************************
 >>>>>>Web XML  :-  Tomcat/webapps/root/WEB-INF
 >>>>>>*******************************************************

I think this is the wrong file. You probably also
have this in server.xml:

<Context path="" docBase="root" debug="0"/>

which relates to Tomcat/webapps/root.

I suggest you get it working by installing your web app in:

Tomcat/webapps/DBTest/

Copy the "examples" web app if its there. Just change occurrences
of "examples" to "DBTest" and install your own:

Tomcat/webapps/DBTest/WEB-INF/web.xml.

test classes in:

Tomcat/webapps/DBTest/WEB-INF/classes

and:

Tomcat/webapps/DBTest/WEB-INF/lib/pg73jdbc3.jar

BTW I recommend that on a development machine you eventually
configure virtual hosts and keep your original tomcat default
webapps installed on one e.g. http://tomcat/ and install your
own stuff elsewhere. e.g. http://DBtest/.

I'd be interested to know how you get on defining data sources.
I've not tried.

Cheers,

Jim Wright

--
Recently completed - Child Brain Injury Trust
Admin System
http://cbitdemo.paneris.org/

Urgently seeking paid work
Java, Linux, XML and much more.
http://be.webz.cz/