Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DC3B2632726 for ; Tue, 1 Jun 2010 22:30:44 -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 31130-09 for ; Wed, 2 Jun 2010 01:30:36 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id C4F6C63273A for ; Tue, 1 Jun 2010 22:30:36 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id o521USxG095202 for ; Tue, 1 Jun 2010 22:30:28 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id o51NcVkN073054 for pgsql-jdbc@postgresql.org; Tue, 1 Jun 2010 20:38:31 -0300 (ADT) (envelope-from news) From: Lew X-Newsgroups: pgsql.interfaces.jdbc Subject: Re: Not able to connect to postgresql database Date: Tue, 01 Jun 2010 19:38:32 -0400 Organization: albasani.net Lines: 40 Message-ID: References: <4C0526EB0200002500031C7D@gw.wicourts.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@albasani.net X-User-ID: HnKR4JdD3O2pieOk/tI9dxVihDALp7IS+tI56eFAkak= In-Reply-To: <4C0526EB0200002500031C7D@gw.wicourts.gov> Cancel-Lock: sha1:GESmm26ZmncNoRFaINUj25lcmp0= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 X-NNTP-Posting-Host: zvMEjqkiEsLgDmRaPKI6WyfnJ+1bYEvhX5RGa2QahAo= To: pgsql-jdbc@postgresql.org 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, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/11 X-Sequence-Number: 20581 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., -- Lew