Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D6C51632978 for ; Wed, 2 Jun 2010 21:29:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 54166-03 for ; Thu, 3 Jun 2010 00:29:20 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from omr-d33.mx.aol.com (omr-d33.mx.aol.com [205.188.249.131]) by mail.postgresql.org (Postfix) with ESMTP id 41D496345B0 for ; Wed, 2 Jun 2010 21:29:20 -0300 (ADT) Received: from imo-da02.mx.aol.com (imo-da02.mx.aol.com [205.188.169.200]) by omr-d33.mx.aol.com (8.14.1/8.14.1) with ESMTP id o530SKMa012996; Wed, 2 Jun 2010 20:28:20 -0400 Received: from PhilFrei@aol.com by imo-da02.mx.aol.com (mail_out_v42.9.) id g.d64.537cf106 (45456); Wed, 2 Jun 2010 20:28:15 -0400 (EDT) Received: from smtprly-dc03.mx.aol.com (smtprly-dc03.mx.aol.com [205.188.170.3]) by cia-mc06.mx.aol.com (v129.4) with ESMTP id MAILCIAMC062-d3c04c06f71eb2; Wed, 02 Jun 2010 20:28:15 -0400 Received: from webmail-d098 (webmail-d098.sim.aol.com [205.188.255.9]) by smtprly-dc03.mx.aol.com (v129.4) with ESMTP id MAILSMTPRLYDC038-d3c04c06f71eb2; Wed, 02 Jun 2010 20:28:14 -0400 X-MB-Message-Type: User Content-Type: text/plain; charset="us-ascii"; format=flowed Cc: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Received: from 69.228.193.82 by webmail-d098.sysops.aol.com (205.188.255.9) with HTTP (WebMailUI); Wed, 02 Jun 2010 20:28:13 -0400 To: craig@postnewspapers.com.au X-AOL-IP: 69.228.193.82 References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> <4C05F409.7060805@postnewspapers.com.au> Date: Wed, 02 Jun 2010 20:28:13 -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 31793-STANDARD In-Reply-To: <4C05F409.7060805@postnewspapers.com.au> Message-Id: <8CCD0CAC9B7220C-D8C-4F1C@webmail-d098.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/30 X-Sequence-Number: 20600 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=20 "preload". The servlet "NearbyTest" has a constructor and a single=20 method "doGet" which is invoked by an HTML page. As the first working=20 statement in the "doGet" method (at this point everything else is=20 commented out), I tried using the recommended statements. Both of them=20 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 at=20 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader. java:1516) at=20 org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader. java:1361) at nearbyGPS.NearByTest.doGet(NearByTest.java:59) ... ---where nearbyGPS is the package and NearByTest is the servlet class. As an experiment I tried importing the Driver class directly, e.g.: import org.postgresql.*; --and the form-- import org.postgresql.Driver; These import statements both compile without complaint. But the same=20 error occurs. I'm afraid that there must be something rather=20 fundamental that I am missing. Is there another stage (prior to the=20 servlet's "doGet") at which the "preloading" should occur? I just tried placing the recommended connection code in the=20 constructor, and get exactly the same error message and stack trace. Eclipse has the option of right-clicking the project and selecting=20 "Configure Build Path". On this project, the PostgreSQL JDBC driver is=20 listed alongside the JRE and Apache libraries. The stack trace indicates code that is part of Apache. Is there=20 possibly something that has to be configured in Apache that is missing? Many, many thanks in advance. ++++++++++++++++++++++++++++++++++++++++++++++++++++ >On 02/06/10 12:56, philfrei@aol.com wrote: >> Hi - I am new to Postgresql (and Eclipse and Tomcat--triple=20 threat),and >> would have posted this question in the general section, but thought=20 it >> might be more appropriate here since it concerns the JDCB. >> >> I have successfully installed and run some example programs from Core >> Java II by Horstmann. I wish to connect to a database from a Java >> Servlet, and tried using the same code and properties as is being=20 used >> in a Java application program (which successfully connects to the=20 same >> db), but am getting the following error when executing the >> DriverManager.getConnection(url, username, password) code: >> >> java.sql.SQLException: No suitable driver found for=20 jdbc:postgresql:gpsdata > >The JRE's JDBC is complaining that it doesn't know what to do with URLs >of type 'jdbc:postgresql'. This means that the PostgreSQL JDBC driver >hasn't been loaded. > >You need to preload the PostgreSQL driver, org.postgresql.Driver , to >register it with JDBC so that JDBC knows to use it for 'postgresql'=20 URLs. > >Load the JDBC driver with with 'Class.forName' if it's on the System >classpath, or (preferably) the classloader that loaded your servelet. > >> Is a different driver needed in the "Servlet" context? > >No, but you might need to load it differently if your container doesn't >use the system classloader. > >You can use the classloader that loaded the currently running object=20 with: > > this.getClass().getClassLoader().loadClass('org.postgresql.Driver'); > >-- >Craig Ringer > >Tech-related writing: http://soapyfrogs.blogspot.com/ >