Обсуждение: JDBC and ClassNotFoundException

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

JDBC and ClassNotFoundException

От
"Geert Verhaag"
Дата:
Dear Members,

I'm currently involved in a database project and have written a GUI in
Java to manipulate a PostgreSQL database (server version 8.2). I've
developed the GUI using NetBeans 5.5 (loaded the
postgresql-8.2-504.jdbc3.jar as JDBC driver) on a Windows XP
professional platform. Building the projetc's jar file works fine and
running the Java program on the Windows XP machine runs smoothly.
Deleting, adding and updating tuples works just fine!

Now I want to run the program's jar file on a Linux platform (OpenSuSe
10.2). So I launch the application with the command: java -jar
AppName.jar at the command prompt, and the program starts correctly, by
displaying the GUI. However when I want to try to connect to the
database by entering the required username and password, I get the
ClassNotFoundException: org.postgresql.Driver runtime error. By the
way, the server on the Windows XP machine is listening for TCP/IP
connections (listen_addresses = '*' in the postgresql.conf file!)

Can anybody give a hint on how to solve this problem? Some CLASSPATH
problem perhaps? Specifying the JDBC driver in the classpath option of
the java-command doesn't seem solve the problem either. I'm afraid that
I don't understand the loading mechanism of the JDBC driver, and perhaps
someone can explain it to me.  Thanks in advance!

Regards,
Gerard Verhaag


==========================================

Dit bericht is uitsluitend bestemd voor de geadresseerde.
Het bericht kan vertrouwelijke informatie bevatten.
Als u dit bericht per abuis hebt ontvangen, wordt u
verzocht onmiddellijk de afzender te informeren. Ook
verzoeken wij u het bericht te vernietigen en de inhoud
niet onder derden te verspreiden of te gebruiken.

This message is intended exclusively for the addressee.
It may contain information that is confidential.
If you are not the intended recipient, we request that
you notify the sender immediately. In that case, we
also request that you destroy the message and that
you neither use the contents nor disclose them in any
manner to third parties.
==========================================


Re: JDBC and ClassNotFoundException

От
Dave Cramer
Дата:
When you specify java -jar .... The classpath isn't used

Dave
On 15-May-07, at 7:04 AM, Geert Verhaag wrote:

> Dear Members,
>
> I'm currently involved in a database project and have written a GUI in
> Java to manipulate a PostgreSQL database (server version 8.2). I've
> developed the GUI using NetBeans 5.5 (loaded the
> postgresql-8.2-504.jdbc3.jar as JDBC driver) on a Windows XP
> professional platform. Building the projetc's jar file works fine and
> running the Java program on the Windows XP machine runs smoothly.
> Deleting, adding and updating tuples works just fine!
>
> Now I want to run the program's jar file on a Linux platform (OpenSuSe
> 10.2). So I launch the application with the command: java -jar
> AppName.jar at the command prompt, and the program starts
> correctly, by
> displaying the GUI. However when I want to try to connect to the
> database by entering the required username and password, I get the
> ClassNotFoundException: org.postgresql.Driver runtime error. By the
> way, the server on the Windows XP machine is listening for TCP/IP
> connections (listen_addresses = '*' in the postgresql.conf file!)
>
> Can anybody give a hint on how to solve this problem? Some CLASSPATH
> problem perhaps? Specifying the JDBC driver in the classpath option of
> the java-command doesn't seem solve the problem either. I'm afraid
> that
> I don't understand the loading mechanism of the JDBC driver, and
> perhaps
> someone can explain it to me.  Thanks in advance!
>
> Regards,
> Gerard Verhaag
>
>
> ==========================================
>
> Dit bericht is uitsluitend bestemd voor de geadresseerde.
> Het bericht kan vertrouwelijke informatie bevatten.
> Als u dit bericht per abuis hebt ontvangen, wordt u
> verzocht onmiddellijk de afzender te informeren. Ook
> verzoeken wij u het bericht te vernietigen en de inhoud
> niet onder derden te verspreiden of te gebruiken.
>
> This message is intended exclusively for the addressee.
> It may contain information that is confidential.
> If you are not the intended recipient, we request that
> you notify the sender immediately. In that case, we
> also request that you destroy the message and that
> you neither use the contents nor disclose them in any
> manner to third parties.
> ==========================================
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
>        choose an index scan if your joining column's datatypes do not
>        match


Re: JDBC and ClassNotFoundException

От
Oliver Jowett
Дата:
Geert Verhaag wrote:
> So I launch the application with the command: java -jar
> AppName.jar at the command prompt

If you specify -jar the JVM ignores any other classpath you set. Either
bundle the driver into your application jar (including it by reference
in a manifest class-path may work, I can't remember), or use -classpath
and an explicit class name instead of -jar.

-O

Re: JDBC and ClassNotFoundException

От
"Mikael Carneholm"
Дата:
Check that postgresql-8.2-504.jdbc3.jar is listed under Class-Path: in
Manifest.mf (located in the meta-inf dir of the AppName.jar file)

Also, listen_addresses only specifies which network interfaces to listen
on (IIRC), you'll have to add a host entry in pg_hba.conf if the IP of
the XP machine isn't already listed there:

host    your_db         your_user         ip_of_the_xp_machine/32
auth_method

(see comments section in pg_hba.conf for description/examples)

/Mikael

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Geert Verhaag
Sent: den 15 maj 2007 13:04
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] JDBC and ClassNotFoundException

Dear Members,

I'm currently involved in a database project and have written a GUI in
Java to manipulate a PostgreSQL database (server version 8.2). I've
developed the GUI using NetBeans 5.5 (loaded the
postgresql-8.2-504.jdbc3.jar as JDBC driver) on a Windows XP
professional platform. Building the projetc's jar file works fine and
running the Java program on the Windows XP machine runs smoothly.
Deleting, adding and updating tuples works just fine!

Now I want to run the program's jar file on a Linux platform (OpenSuSe
10.2). So I launch the application with the command: java -jar
AppName.jar at the command prompt, and the program starts correctly, by
displaying the GUI. However when I want to try to connect to the
database by entering the required username and password, I get the
ClassNotFoundException: org.postgresql.Driver runtime error. By the
way, the server on the Windows XP machine is listening for TCP/IP
connections (listen_addresses = '*' in the postgresql.conf file!)

Can anybody give a hint on how to solve this problem? Some CLASSPATH
problem perhaps? Specifying the JDBC driver in the classpath option of
the java-command doesn't seem solve the problem either. I'm afraid that
I don't understand the loading mechanism of the JDBC driver, and perhaps
someone can explain it to me.  Thanks in advance!

Regards,
Gerard Verhaag


==========================================

Dit bericht is uitsluitend bestemd voor de geadresseerde.
Het bericht kan vertrouwelijke informatie bevatten.
Als u dit bericht per abuis hebt ontvangen, wordt u
verzocht onmiddellijk de afzender te informeren. Ook
verzoeken wij u het bericht te vernietigen en de inhoud
niet onder derden te verspreiden of te gebruiken.

This message is intended exclusively for the addressee.
It may contain information that is confidential.
If you are not the intended recipient, we request that
you notify the sender immediately. In that case, we
also request that you destroy the message and that
you neither use the contents nor disclose them in any
manner to third parties.
==========================================


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

Re: JDBC and ClassNotFoundException

От
"Geert Verhaag"
Дата:
Hi,

Thanks for the various tips! The statement to bundle the JDBC driver
into the application triggered me to take a better look at the build
proces using NetBeans.

The lib subdirectory within the dist directory contains the JDBC driver
among other things. The README file within the dist directory just gave
the solution:

Generate a zip/tar file from the dist directory! This archive is used
to distribute the application. After I unzipped the archive on the Linux
PC everything worked just fine!

Regards,
Gerard Verhaag


==========================================

Dit bericht is uitsluitend bestemd voor de geadresseerde.
Het bericht kan vertrouwelijke informatie bevatten.
Als u dit bericht per abuis hebt ontvangen, wordt u
verzocht onmiddellijk de afzender te informeren. Ook
verzoeken wij u het bericht te vernietigen en de inhoud
niet onder derden te verspreiden of te gebruiken.

This message is intended exclusively for the addressee.
It may contain information that is confidential.
If you are not the intended recipient, we request that
you notify the sender immediately. In that case, we
also request that you destroy the message and that
you neither use the contents nor disclose them in any
manner to third parties.
==========================================