pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nico <nicohmail-postgresql@yahoo.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: Another java connect problem
Date: Mon, 4 Apr 2005 13:56:43 +0200
Message-ID: <d2ra23$2fem$1@news.hub.org> (raw)
References: <425121BB.8020603@statkart.no>

Why do you use 'Class.forName("org.postgresql.Driver").newInstance();'? Just 
use 'Class.forName("org.postgresql.Driver");'
Oh, by the way, it's probably something you forgot in your e-mail, but
DriverManager.getConnection(url, "user", "password);
is not correct, it has to be:
DriverManager.getConnection(url, "user", "password");
That's the way it works for me...

Nico.

""Espen Isaksen"" <espen.isaksen@statkart.no> schreef in bericht 
news:425121BB.8020603@statkart.no...
> Hi!
>
> I have studied all the different questions where people have trouble
> connecting to PostgreSQL through Java, but it doesn't help me
> much. This is a program I first compiled on a Mac and I have no
> problems at all there. Now I am on Fedora Linux.
>
> First my code:
> Connection dbcon;
> java.sql.Connection conn;
> String url = "jdbc:postgresql://localhost:5432/espen";
>  try {
>        Class.forName("org.postgresql.Driver").newInstance();
>    }
>    catch( ClassNotFoundException cnfex ) {
>        System.out.println("Class not found!");
>    } //end catch
>   conn = DriverManager.getConnection(url, "user", "password);
>    Statement stmt = conn.createStatement();
>    s = conn.createStatement();
>
>
> I compile by using this command:
> javac @files -classpath postgis.jar:postgresql.jar (where files include a 
> list of all the .java files)
>
> No problems compiling.
>
> I try to run by:
> java road_generalization -verbose -classpath postgis.jar:postgresql.jar
>
> Then I get the usual error message:
>
> Unable to connect
> java.sql.SQLException: No suitable driver
>        at java.sql.DriverManager.getConnection(Unknown Source)
>        at java.sql.DriverManager.getConnection(Unknown Source)
>        at DataUthenter.connectPostgres(DataUthenter.java:67)
>        at DataUthenter.<init>(DataUthenter.java:31)
>        at road_generalization.<init>(road_generalization.java:99)
>        at road_generalization.main(road_generalization.java:383)
>
> I have tried to change the code in a lot of different ways, but it does 
> not
> seem to help much. Can anybody give me some insight in why this
> doesn't work. Is my "run command" not correct?
>
> Espen Isaksen
> http://www.espenisaksen.com
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
> 





view thread (6+ messages)  latest in thread

Message-ID: <d2ra23$2fem$1@news.hub.org>
Permalink:  ../d2ra23$2fem$1@news.hub.org/
Also on:    postgresql.org/message-id/d2ra23$2fem$1@news.hub.org

 · 

reply

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: nicohmail-postgresql@yahoo.com
  Subject: Re: Another java connect problem
  In-Reply-To: <d2ra23$2fem$1@news.hub.org>
  References: <425121BB.8020603@statkart.no> <d2ra23$2fem$1@news.hub.org>

* 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