Skip site navigation (1) Skip section navigation (2)

Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"

From: philfrei(at)aol(dot)com
To: craig(at)postnewspapers(dot)com(dot)au
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: 2010-06-04 05:48:20
Message-ID: 8CCD1C0ABE41498-C10-62A5@webmail-d048.sysops.aol.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
HI - Thank you both Craig and Manohar.

There is no .WAR file in this project. So I am unable to follow related 
advice.

There is a .CLASSPATH file stored with the project. It has the 
following entry pertaining to the jdbc:
<classpathentry kind="con" 
path="org.eclipse.datatools.connectivity.jdt.DRIVERLIBRARY/PostgreSQL 
JDBC Driver"/>

There is also a .project file with various <buildSpec> and 
<buildCommand> tags, and a .jsdtscope file with <classpath> and 
<classpathentry> tags. But neither has any reference to the JDBC.

I'm thinking maybe I will refer back to the Eclipse Forum with this 
research, as they will may know better if the registration is correct 
and proper.

If I do get an answer, I will follow up here just in case anyone else 
ends up pursuing the same matter.

With much appreciation,

Phil Freihofner





-----Original Message-----
From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: philfrei(at)aol(dot)com
Cc: pgsql-jdbc(at)postgresql(dot)org
Sent: Wed, Jun 2, 2010 7:19 pm
Subject: Re: jdbc works in java app, fails in servlet: "no suitable 
jdbc found"


On 3/06/2010 8:28 AM, philfrei(at)aol(dot)com wrote: 
> Thank you for the reply! 
> 
>> You need to preload the PostgreSQL driver... 
> 
> Being new to this, I find myself second-guessing words as simple as 
> "preload". The servlet "NearbyTest" has a constructor and a single 
> method "doGet" which is invoked by an HTML page. As the first working 
> statement in the "doGet" method (at this point everything else is 
> commented out), I tried using the recommended statements. Both of 
them 
> elicited the same error message: 
> 
> try { 
> // Class.forName("org.postgresql.Driver"); 
> this.getClass().getClassLoader().loadClass("org.postgresql.Driver"); 
> } catch (ClassNotFoundException e1) { 
> e1.printStackTrace(); 
> } 
> 
> java.lang.ClassNotFoundException: org.postgresql.Driver 
 
I'd say your classpath is misconfigured; the classloader cannot find 
PostgreSQL. 
 
On web service containers sometimes the dependencies for the servelet 
must all be embedded in a .war with the serverlet jar. Is that the case 
here? 
 
> Is there another stage (prior to the servlet's 
> "doGet") at which the "preloading" should occur? 
 
Nope, just loading the class is sufficient. 
 
> The stack trace indicates code that is part of Apache. Is there 
possibly 
> something that has to be configured in Apache that is missing? 
 
Well the trace refers to org.apache.catalina.loader.WebappClassLoader , 
which is a part of Apache Catalina. It has nothing to do with the 
Apache web server except that they're both from the Apache project. 
 
Catalina is Tomcat's servlet container. 
 
That further suggests that you need to configure your classpath in your 
web app environment, or have an issue with how your app and 
dependencies are packaged. I've only done this stuff with Maven & 
Netbeans targeting Glassfish, so I can't really offer much help with 
the details of doing it right using Eclipse's build system and a Tomcat 
target. 
 
-- 
Craig Ringer 


In response to

Responses

pgsql-jdbc by date

Next:From: John R PierceDate: 2010-06-04 06:40:36
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Previous:From: Guy RouillierDate: 2010-06-03 23:51:17
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group