pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problems loading the driver
3+ messages / 3 participants
[nested] [flat]

* Problems loading the driver
@ 2005-06-25 04:41 enrique.ibarra@mac.com
  2005-06-25 05:22 ` Re: Problems loading the driver Oliver Jowett <oliver@opencloud.com>
  0 siblings, 1 reply; 3+ messages in thread

From: enrique.ibarra@mac.com @ 2005-06-25 04:41 UTC (permalink / raw)
  To: pgsql-jdbc

Hello:

I am trying to compile a very simple Java J2SE program that will  
connect to a Postgres database. I am using:
* an Apple computer running Mac OS/X 10.4
* Postgres 8.0
* JDBC driver postgresql-8.0-311.jdbc3.jar

The JDBC jar file IS in the CLASSPATH environment variable. The code  
of the program is the following:

     public static void main (String[] args) {

         try {
             Class.forName ("org.postgresql.Driver");
         } catch (ClassNotFoundException e) {
             System.out.println (e.getMessage ());
             e.printStackTrace ();
         }

The program compiles fine but the error message I get when I run the  
program is the following:

[Session started at 2005-06-24 23:32:14 -0500.]
org.postgresql.Driver
java.lang.ClassNotFoundException: org.postgresql.Driver
     at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:141)
     at gastos.main(gastos.java:17)

I have tried placing the JDBC jar file at different directories while  
adjusting the CLASSPATH variable but I keep getting the same annoying  
error. I also tried the -cp flag when invoking 'java' to execute the  
program, but it does not work. I ran out of ideas and the exercise is  
becoming very frustrating. Any suggestions will be highly  
appreciated. Thanks a lot in advance.

Regards,

Enrique

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problems loading the driver
  2005-06-25 04:41 Problems loading the driver enrique.ibarra@mac.com
@ 2005-06-25 05:22 ` Oliver Jowett <oliver@opencloud.com>
  2005-06-27 18:22   ` Re: Problems loading the driver Enrique Ibarra <enrique.ibarra@mac.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Oliver Jowett @ 2005-06-25 05:22 UTC (permalink / raw)
  To: enrique.ibarra@mac.com; +Cc: pgsql-jdbc

enrique.ibarra@mac.com wrote:

> The JDBC jar file IS in the CLASSPATH environment variable. The code of
> the program is the following:

> org.postgresql.Driver
> java.lang.ClassNotFoundException: org.postgresql.Driver

This means that the driver jar *isn't* in your classpath.

What is the exact value of your CLASSPATH, have you exported the
CLASSPATH environment variable, where have you placed the driver jar,
and what is the Java command line you are trying?

-O



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Problems loading the driver
  2005-06-25 04:41 Problems loading the driver enrique.ibarra@mac.com
  2005-06-25 05:22 ` Re: Problems loading the driver Oliver Jowett <oliver@opencloud.com>
@ 2005-06-27 18:22   ` Enrique Ibarra <enrique.ibarra@mac.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Enrique Ibarra @ 2005-06-27 18:22 UTC (permalink / raw)
  To: Oliver Jowett <oliver@opencloud.com>; +Cc: pgsql-jdbc

Oliver, thank you very much for your quick response. It seems that I  
will have to check this problem with Apple support. The jar driver is  
in fact in the CLASSPATH variable but somehow its value is not being  
correctly read by java. I was originally working with Xcode (Apple's  
IDE). I tried specifying both the CLASSPATH environment variable and  
java's -cp switch in the IDE but it did not work. Then I switched to  
old-fashioned emacs and a command terminal and I was able to make the  
program run, but only when I specify the -cp option in the java  
command line. If I do not specify the -cp switch then the program  
does not run (even though the jar driver is in the CLASSPATH). I have  
not been able to make this program run from the Xcode IDE. Here is  
the output of the command terminal to illustrate this problem. Thanks  
again.

{~/Ixe/Proyectos/tarme}% javac actgastos.java
{~/Ixe/Proyectos/tarme}% echo $CLASSPATH
/usr/local/lib/postgresql.jar:.:
{~/Ixe/Proyectos/tarme}% java actgastos gastos.csv
org.postgresql.Driver
java.lang.ClassNotFoundException: org.postgresql.Driver
         at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java: 
274)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java: 
302)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:141)
         at actgastos.main(actgastos.java:8)
No suitable driver
java.sql.SQLException: No suitable driver
         at java.sql.DriverManager.getConnection(DriverManager.java:532)
         at java.sql.DriverManager.getConnection(DriverManager.java:171)
         at actgastos.main(actgastos.java:15)
{~/Ixe/Proyectos/tarme}% java -cp /usr/local/lib/postgresql.jar:.:  
actgastos gastos.csv
{~/Ixe/Proyectos/tarme}%


On Jun 25, 2005, at 12:22 AM, Oliver Jowett wrote:

> enrique.ibarra@mac.com wrote:
>
>
>> The JDBC jar file IS in the CLASSPATH environment variable. The  
>> code of
>> the program is the following:
>>
>
>
>> org.postgresql.Driver
>> java.lang.ClassNotFoundException: org.postgresql.Driver
>>
>
> This means that the driver jar *isn't* in your classpath.
>
> What is the exact value of your CLASSPATH, have you exported the
> CLASSPATH environment variable, where have you placed the driver jar,
> and what is the Java command line you are trying?
>
> -O
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-06-27 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-25 04:41 Problems loading the driver enrique.ibarra@mac.com
2005-06-25 05:22 ` Oliver Jowett <oliver@opencloud.com>
2005-06-27 18:22   ` Enrique Ibarra <enrique.ibarra@mac.com>

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