Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0FF1F6323AF for ; Sat, 5 Jun 2010 04:12:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 93620-02 for ; Sat, 5 Jun 2010 07:12:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from imr-mb01.mx.aol.com (imr-mb01.mx.aol.com [64.12.207.164]) by mail.postgresql.org (Postfix) with ESMTP id 6698B6321A7 for ; Sat, 5 Jun 2010 04:12:02 -0300 (ADT) Received: from imo-da01.mx.aol.com (imo-da01.mx.aol.com [205.188.169.199]) by imr-mb01.mx.aol.com (8.14.1/8.14.1) with ESMTP id o557BjQI019100; Sat, 5 Jun 2010 03:11:45 -0400 Received: from PhilFrei@aol.com by imo-da01.mx.aol.com (mail_out_v42.9.) id o.dfd.9d80cea (37588); Sat, 5 Jun 2010 03:11:40 -0400 (EDT) Received: from smtprly-ma01.mx.aol.com (smtprly-ma01.mx.aol.com [64.12.207.140]) by cia-mb06.mx.aol.com (v129.4) with ESMTP id MAILCIAMB061-5c494c09f8ab285; Sat, 05 Jun 2010 03:11:40 -0400 Received: from webmail-d019 (webmail-d019.sim.aol.com [205.188.181.27]) by smtprly-ma01.mx.aol.com (v129.4) with ESMTP id MAILSMTPRLYMA017-5c494c09f8ab285; Sat, 05 Jun 2010 03:11:39 -0400 X-MB-Message-Type: User Content-Type: text/plain; charset="utf-8"; format=flowed Cc: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Received: from 69.228.214.47 by webmail-d019.sysops.aol.com (205.188.181.27) with HTTP (WebMailUI); Sat, 05 Jun 2010 03:11:38 -0400 To: craig@postnewspapers.com.au, pierce@hogranch.com, manoharbhattarai@gmail.com X-AOL-IP: 69.228.214.47 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> Date: Sat, 05 Jun 2010 03:11:38 -0400 From: philfrei@aol.com Content-Transfer-Encoding: quoted-printable Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found" X-MB-Message-Source: WebUI X-Mailer: AOL Webmail 31888-STANDARD In-Reply-To: <8CCD1C0ABE41498-C10-62A5@webmail-d048.sysops.aol.com> Message-Id: <8CCD29579E64490-22E4-8BA9@webmail-d019.sysops.aol.com> X-AOL-SENDER: PhilFrei@aol.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/42 X-Sequence-Number: 20612 This is to follow up with the solution I was given at the Eclipse=20 "Newbies" forum. Thank you Russell Bateman! With a right-click on the project, and a selection of "Properties," one=20 can navigate to "Java EE Module Dependencies." At this point, one can=20 "select the utility project, JAR or classpath entry to add as a Web=20 Library dependency." One of the choices offered was in fact the=20 PostgreSQL JDBC Driver library. After checking the option box, I was=20 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=20 the "Markers" area was the following Classpath Warning: Classpath entry=20 org.eclipse.datatools.connectivity.jdt.DRIVERLIBRARY/PostgreSQL JDBC=20 Driver will not be exported or published. Runtime=20 ClassNotFoundExceptions may result. Indeed, the problem was that the Driver class from the JDBC was not=20 being found. But once the above checkbox was selected, the warning=20 disappeared. Do I understand this, or all the suggestions given? Not a whole lot.=20 I'm guessing that somehow the Apache server is executing code that is=20 not referencing the usual Java packages and libraries, and it needs to=20 have these dependencies addressed. I can't say the location for this is=20 exactly intuitive. But then, I am totally new to this and maybe it will=20 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=20 was started from scratch and a bit of cut-and-paste. It was not created=20 from a WAR and I have yet to package it into a WAR. Maybe that answers=20 his question? Thanks again for everyone who took time to address this question! Phil Freihofner =C2=A0 =C2=A0 -----Original Message-----=C2=A0 From: Craig Ringer =C2=A0 To: philfrei@aol.com=C2=A0 Cc: pgsql-jdbc@postgresql.org=C2=A0 Sent: Wed, Jun 2, 2010 7:19 pm=C2=A0 Subject: Re: jdbc works in java app, fails in servlet: "no suitable=20 jdbc found"=C2=A0 =C2=A0 On 3/06/2010 8:28 AM, philfrei@aol.com wrote:=C2=A0=C2=A0 > Thank you for the reply!=C2=A0=C2=A0 >=C2=A0=C2=A0 >> You need to preload the PostgreSQL driver...=C2=A0=C2=A0 >=C2=A0=C2=A0 > Being new to this, I find myself second-guessing words as simple as=C2= =A0=C2=A0 > "preload". The servlet "NearbyTest" has a constructor and a single=C2=A0= =C2=A0 > method "doGet" which is invoked by an HTML page. As the first=20 working=C2=A0=C2=A0 > statement in the "doGet" method (at this point everything else is=C2=A0= =C2=A0 > commented out), I tried using the recommended statements. Both of=20 them=C2=A0=C2=A0 > elicited the same error message:=C2=A0=C2=A0 >=C2=A0=C2=A0 > try {=C2=A0=C2=A0 > // Class.forName("org.postgresql.Driver");=C2=A0=C2=A0 > this.getClass().getClassLoader().loadClass("org.postgresql.Driver");=C2= =A0=C2=A0 > } catch (ClassNotFoundException e1) {=C2=A0=C2=A0 > e1.printStackTrace();=C2=A0=C2=A0 > }=C2=A0=C2=A0 >=C2=A0=C2=A0 > java.lang.ClassNotFoundException: org.postgresql.Driver=C2=A0=C2=A0 =C2=A0=C2=A0 I'd say your classpath is misconfigured; the classloader cannot find=20 PostgreSQL.=C2=A0=C2=A0 =C2=A0=C2=A0 On web service containers sometimes the dependencies for the servelet=20 must all be embedded in a .war with the serverlet jar. Is that the case=20 here?=C2=A0=C2=A0 =C2=A0=C2=A0 > Is there another stage (prior to the servlet's=C2=A0=C2=A0 > "doGet") at which the "preloading" should occur?=C2=A0=C2=A0 =C2=A0=C2=A0 Nope, just loading the class is sufficient.=C2=A0=C2=A0 =C2=A0=C2=A0 > The stack trace indicates code that is part of Apache. Is there=20 possibly=C2=A0=C2=A0 > something that has to be configured in Apache that is missing?=C2=A0=C2= =A0 =C2=A0=C2=A0 Well the trace refers to org.apache.catalina.loader.WebappClassLoader ,=20 which is a part of Apache Catalina. It has nothing to do with the=20 Apache web server except that they're both from the Apache project.=C2=A0= =C2=A0 =C2=A0=C2=A0 Catalina is Tomcat's servlet container.=C2=A0=C2=A0 =C2=A0=C2=A0 That further suggests that you need to configure your classpath in your=20 web app environment, or have an issue with how your app and=20 dependencies are packaged. I've only done this stuff with Maven &=20 Netbeans targeting Glassfish, so I can't really offer much help with=20 the details of doing it right using Eclipse's build system and a Tomcat=20 target.=C2=A0=C2=A0 =C2=A0=C2=A0 --=C2=A0=C2=A0 Craig Ringer=C2=A0=C2=A0 =C2=A0