Re: Not able to connect to postgresql database - Mailing list pgsql-jdbc

From Lew
Subject Re: Not able to connect to postgresql database
Date
Msg-id hu45l7$d93$1@news.albasani.net
Whole thread Raw
In response to Re: Not able to connect to postgresql database  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Responses Re: Not able to connect to postgresql database  (Manohar Bhattarai <manoharbhattarai@gmail.com>)
List pgsql-jdbc
On 06/01/2010 04:27 PM, Kevin Grittner wrote:
Manohar Bhattarai wrote:
>
>> shows an exception that it cannot find driver.
>
>> Please help me and let me know what i am doing wrong and what i am
>> missing.
>
> The jar is not on your classpath, or you are not spelling the class
> name ("org.postgresql.Driver") correctly.  I don't know of any other
> reason that the recommended class loading:
>
>      Class.forName("org.postgresql.Driver");

Just as an aside, nowadays the recommended way from Sun is to load a driver is
through DataSource descriptors, which has its advantages but is a lot less
simple at first.  With JPA you configure the data source in the
"persistence.xml" file for a local application, other XML files like
"context.xml" for app servers.

The 'Class.forName()' method is reliable but don't fall into the trap of
calling it more than once per program execution.

> would throw a ClassNotFoundException.  (If that's not what you're
> doing, or that's not the statement on which it fails, or that's not
> your exception, you need to give us more clues.)

All techniques require proper placement of the driver JAR file in your
classpath.  What that classpath is depends utterly on how you package and
deploy your app.

There's clear documentation on java.sun.com about JDBC, and about how to
specify the classpath for the "java ... foo.foo" ("-classpath" option) and
"java -jar foo.jar" (manifest file "Class-path:" entry) commands.  For the
various app servers you have to check the rules for the particular app server,
e.g.,
<http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html>

--
Lew

pgsql-jdbc by date:

Previous
From: Maciek Sakrejda
Date:
Subject: Re: Not able to connect to postgresql database
Next
From: philfrei@aol.com
Date:
Subject: jdbc works in java app, fails in servlet: "no suitable jdbc found"