Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DA695633C57 for ; Wed, 2 Jun 2010 03:05:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 65461-01 for ; Wed, 2 Jun 2010 06:05:37 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.4.227.11]) by mail.postgresql.org (Postfix) with ESMTP id DCDED632B48 for ; Wed, 2 Jun 2010 03:05:37 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id C58F479245; Wed, 2 Jun 2010 14:05:28 +0800 (WST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 90FA3AF926; Wed, 2 Jun 2010 14:03:52 +0800 (WST) Message-ID: <4C05F409.7060805@postnewspapers.com.au> Date: Wed, 02 Jun 2010 14:02:49 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: philfrei@aol.com CC: pgsql-jdbc@postgresql.org Subject: Re: jdbc works in java app, fails in servlet: "no suitable jdbc found" References: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> In-Reply-To: <8CCD02714A2791E-E2C-7A83@webmail-m042.sysops.aol.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/13 X-Sequence-Number: 20583 On 02/06/10 12:56, philfrei@aol.com wrote: > Hi - I am new to Postgresql (and Eclipse and Tomcat--triple threat),and > would have posted this question in the general section, but thought 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 used > in a Java application program (which successfully connects to the 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 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' 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 with: this.getClass().getClassLoader().loadClass('org.postgresql.Driver'); -- Craig Ringer Tech-related writing: http://soapyfrogs.blogspot.com/