Trouble connecting

Поиск
Список
Период
Сортировка
Искать

Trouble connecting

От:
Antonie C Malan <malan2000@optusnet.com.au>
Дата:
Hi All, 

I have a Mandrake 9.0 setup.  The Postgresql came with it as did the drivers.  
I also downloaded an driver package from the postgresql site, no luck.

-- These are the relevant bits of my code:
String url = "jdbc:postgresql://localhost:5432/Patients";
        Connection conn = null;
        java.sql.Statement stmnt = null;
        java.sql.ResultSet result = null;
        try{
          Class.forName("org.postgresql.Driver");
          conn = DriverManager.getConnection(url, user, pwd);
User and password (pwd) are fed in as string from the command line.

This is as far as it gets before an exception is thrown.

I did import java.sql.* and tried three different driver packages -
jdbc7.1-1.2.jar, jdbc7.2dev-1.2.jar and downloaded and tried pgjdbc2.jar from 
the PostgreSQL site.  At different times they all were in the classpath.  
These are all precompiled packages and should run on my JDK1.4.0

The following exception is thrown:
java.sql.SQLException: Driver not found for URL: 
jdbc:postgresql://localhost:5432/Patients


Note that it is not a ClassNotFoundException, so it seems the driverpackage is 
found and used.  I tried different things with the URL, like:
jdbc:postgresql:Patients
all to no avail.

I've also tried to get a driver that supports this URL in a roundabout way 
doing something like DriverManager.getDriver(String url) - It returns a  null 
driver. Details may be different for this last ploy - I don't have the API 
open at the moment. Looks as if there is something wrong with the drivers 
I've got.  I can connect to the database from a term and using Postgresql 
Access.

I am out of ideas with my back against the wall.  I'll be grateful for any 
help.

Chris Malan
malan2000@optusnet.com.au

Re: Trouble connecting

От:
john guthrie <jguthrie@psynapsetech.com>
Дата:
i'll start by saying i don't know what the problem is here. the url 
looks fine to me.

you probably know this, but my understanding is that what happens in 
jdbc is when the org.postgresql.Driver class gets loaded (during the 
Class.forname()) in it's static initializer it registers itself as a 
jdbc driver with the DriverManager. then when 
DriverManager.getConnection() is called, the DriverManager runs through 
its list of jdbc drivers and presents each of them with the first part 
of the url ("jdbc:postgresql"). the first driver that recognizes the url 
then returns a connection.

so, either you have another driver in your DriverManager that is 
short-circuiting the request or your postgresql is not recognizing the 
"jdbc:postgresql" string. neither seems likely to me. maybe there's some 
weird unprintable in your url?

note that this error has nothing to do at all with whether the database 
is up and running, much less whether your username and password are 
valid - you're not even getting that far.

looking at the code for org.postgresql.Driver.java from 7.2.2 doesn't 
point anything out either (that i can see). it checks if the first token 
(":"- delimited, among others) is "jdbc" or "postgresql", and it pretty 
much accepts the second piece.

so if i were you, i think i'd get out the old debugger (aka 
"System.out.println") and start putting some statements in 
org.postgresql.Driver

sorry i'm not more help here,
john

Antonie C Malan wrote:
> Hi All, 
> 
> I have a Mandrake 9.0 setup.  The Postgresql came with it as did the drivers.  
> I also downloaded an driver package from the postgresql site, no luck.
> 
> -- These are the relevant bits of my code:
> String url = "jdbc:postgresql://localhost:5432/Patients";
>         Connection conn = null;
>         java.sql.Statement stmnt = null;
>         java.sql.ResultSet result = null;
>         try{
>           Class.forName("org.postgresql.Driver");
>           conn = DriverManager.getConnection(url, user, pwd);
> User and password (pwd) are fed in as string from the command line.
> 
> This is as far as it gets before an exception is thrown.
> 
> I did import java.sql.* and tried three different driver packages -
> jdbc7.1-1.2.jar, jdbc7.2dev-1.2.jar and downloaded and tried pgjdbc2.jar from 
> the PostgreSQL site.  At different times they all were in the classpath.  
> These are all precompiled packages and should run on my JDK1.4.0
> 
> The following exception is thrown:
> java.sql.SQLException: Driver not found for URL: 
> jdbc:postgresql://localhost:5432/Patients
> 
> 
> Note that it is not a ClassNotFoundException, so it seems the driverpackage is 
> found and used.  I tried different things with the URL, like:
> jdbc:postgresql:Patients
> all to no avail.
> 
> I've also tried to get a driver that supports this URL in a roundabout way 
> doing something like DriverManager.getDriver(String url) - It returns a  null 
> driver. Details may be different for this last ploy - I don't have the API 
> open at the moment. Looks as if there is something wrong with the drivers 
> I've got.  I can connect to the database from a term and using Postgresql 
> Access.
> 
> I am out of ideas with my back against the wall.  I'll be grateful for any 
> help.
> 
> Chris Malan
> malan2000@optusnet.com.au
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

-- 
john guthrie
jguthrie@psynapsetech.com (was jguthrie@air.org)

Re: Trouble connecting

От:
Jean-Christian Imbeault <jc@mega-bucks.co.jp>
Дата:
Hvae a look at example 12-2 on this page:

http://www.commandprompt.com/ppbook/x20856.htm

I found the code quite useful in trying to debug a JDBC driver 
loading/connectin problem.

Jc

FAQ