Обсуждение: Another java connect problem

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

Another java connect problem

От
"Espen Isaksen"
Дата:
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


Re: Another java connect problem

От
"Nico"
Дата:
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
>



Re: Another java connect problem

От
Paul Thomas
Дата:
On 04/04/2005 12:15 Espen Isaksen wrote:
> I try to run by:
> java road_generalization -verbose -classpath postgis.jar:postgresql.jar

Try putting you command line in the correct order.

--
Paul Thomas
+------------------------------+-------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for Business           |
| Computer Consultants         | http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+-------------------------------------------+

Re: Another java connect problem

От
Dave Cramer
Дата:
Hi,

What is the postgis.jar doing? Does it still implement it's own version
of the jdbc driver ?

the newinstance thing doesn't matter it will still work that way.

Try it without the postgis.jar, it may be loading its version of the driver.

Dave

Espen Isaksen wrote:

> 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
>
>

--
Dave Cramer
http://www.postgresintl.com
519 939 0336
ICQ#14675561


Re: Another java connect problem

От
Espen Isaksen
Дата:
Hi!

I just got it working. Well at least past that problem. Now I have a new one. :-)
It was solved by correcting the java command. Apparantly it gives this error
if you put you .class file before the options.

Postgis is a GIS(Geographic information System) extension to Postgresql.
Check out http://www.postgis.org/.

Thanks, Espen(using a new e-mail address at the moment)



On Tuesday, April 05, 2005, at 02:11PM, Dave Cramer <pg@fastcrypt.com> wrote:

>Hi,
>
>What is the postgis.jar doing? Does it still implement it's own version
>of the jdbc driver ?
>
>the newinstance thing doesn't matter it will still work that way.
>
>Try it without the postgis.jar, it may be loading its version of the driver.
>
>Dave
>
>Espen Isaksen wrote:
>
>> 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
>>
>>
>
>--
>Dave Cramer
>http://www.postgresintl.com
>519 939 0336
>ICQ#14675561
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 7: don't forget to increase your free space map settings
>
>


-------------------------
Espen Isaksen
Visit my website:
http://www.espenisaksen.com

Re: Another java connect problem

От
Markus Schaber
Дата:
Hi, Dave,

Dave Cramer schrieb:

> What is the postgis.jar doing? Does it still implement it's own version
> of the jdbc driver?
> the newinstance thing doesn't matter it will still work that way.
> Try it without the postgis.jar, it may be loading its version of the
> driver.

Where do you have this information from? All PostGIS versions I know
(0.7.x up to current 1.0.0RCX) do not carry any org.postgresql.Driver
class with them.

1.0 versions carry _subclasses_ of org.postgresql.Driver with them.

I have to admit that, _during compilation_, postgis uses their own
copies of org.postgresql.Connection and org.postgresql.PGConnection, but
those are not packed into postgis.jar. This ugly trick is necessary
because the postgresql.jar incompatibly renamed this class between 7.2
and 7.3, and the Debian/GIS people still want to support debian stable
which carries 7.2 with it.

Markus

Вложения