From: Lew <noone@lewscanon.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Not able to connect to postgresql database
Date: Tue, 01 Jun 2010 19:38:32 -0400
Message-ID: <hu45l7$d93$1@news.albasani.net> (raw)
In-Reply-To: <4C0526EB0200002500031C7D@gw.wicourts.gov>
References: <AANLkTinBl2QsPy0vCg0gN1fzy96ttltXpK0TVGqeiRlU@mail.gmail.com>
<4C0526EB0200002500031C7D@gw.wicourts.gov>
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
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: noone@lewscanon.com
Subject: Re: Not able to connect to postgresql database
In-Reply-To: <hu45l7$d93$1@news.albasani.net>
References: <AANLkTinBl2QsPy0vCg0gN1fzy96ttltXpK0TVGqeiRlU@mail.gmail.com> <4C0526EB0200002500031C7D@gw.wicourts.gov> <hu45l7$d93$1@news.albasani.net>
* 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