pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: philfrei@aol.com
To: craig@postnewspapers.com.au
To: pierce@hogranch.com
To: manoharbhattarai@gmail.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
Date: Sat, 05 Jun 2010 03:11:38 -0400
Message-ID: <8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com> (raw)
In-Reply-To: <8CCD1C0ABE41498-C10-62A5@webmail-d048.sysops.aol.com>
References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com>
	<4C05F409.7060805@postnewspapers.com.au>
	<8CCD0CAC9B7220C-D8C-4F1C@webmail-d098.sysops.aol.com>
	<4C071135.3020607@postnewspapers.com.au>
	<8CCD1C0ABE41498-C10-62A5@webmail-d048.sysops.aol.com>

This is to follow up with the solution I was given at the Eclipse 
"Newbies" forum. Thank you Russell Bateman!

With a right-click on the project, and a selection of "Properties," one 
can navigate to "Java EE Module Dependencies." At this point, one can 
"select the utility project, JAR or classpath entry to add as a Web 
Library dependency." One of the choices offered was in fact the 
PostgreSQL JDBC Driver library. After checking the option box, I was 
able to run the servlet and have it connect to the PostgreSQL database.

A further clue (which I overlooked until this afternoon) was that in 
the "Markers" area was the following Classpath Warning:

Classpath entry 
org.eclipse.datatools.connectivity.jdt.DRIVERLIBRARY/PostgreSQL JDBC 
Driver will not be exported or published. Runtime 
ClassNotFoundExceptions may result.

Indeed, the problem was that the Driver class from the JDBC was not 
being found. But once the above checkbox was selected, the warning 
disappeared.

Do I understand this, or all the suggestions given? Not a whole lot. 
I'm guessing that somehow the Apache server is executing code that is 
not referencing the usual Java packages and libraries, and it needs to 
have these dependencies addressed. I can't say the location for this is 
exactly intuitive. But then, I am totally new to this and maybe it will 
start to make more sense as I get further along.

One person was asking why I have no WAR file. The code for this project 
was started from scratch and a bit of cut-and-paste. It was not created 
 from a WAR and I have yet to package it into a WAR. Maybe that answers 
his question?

Thanks again for everyone who took time to address this question!

Phil Freihofner

 
 
-----Original Message----- 
From: Craig Ringer <craig@postnewspapers.com.au> 
To: philfrei@aol.com 
Cc: pgsql-jdbc@postgresql.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@aol.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  
 




view thread (14+ messages)  latest in thread

Message-ID: <8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com>
Permalink:  ../8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com/
Also on:    postgresql.org/message-id/8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: philfrei@aol.com, craig@postnewspapers.com.au, pierce@hogranch.com, manoharbhattarai@gmail.com
  Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found"
  In-Reply-To: <8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com>
  References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> <4C05F409.7060805@postnewspapers.com.au> <8CCD0CAC9B7220C-D8C-4F1C@webmail-d098.sysops.aol.com> <4C071135.3020607@postnewspapers.com.au> <8CCD1C0ABE41498-C10-62A5@webmail-d048.sysops.aol.com> <8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox