Re: I just can't use the org.postgresql.Driver class... Please help!

Lists: pgsql-jdbc
From: Kamal <kalotus(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: I just can't use the org.postgresql.Driver class... Please help!
Date: 2006-04-05 18:53:58
Message-ID: 3a829cca0604051153i71f8a212n5992243608f6f2cb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Hi everybody.
Thi is my first time trying to use postgresql jdbc and I'm very frustrated.

This is my env:

C:\>java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

I have these files in the same directory:

Simple source file (JasperReportsTest.java):

public class JasperReportsTest
{
public static void main(String[] args)
{

Class.forName("org.postgresql.Driver");

}
}

Simple batch file to compile it (JasperReportsTest.bat):

set CLASSPATH=postgresql-8.1-405.jdbc3.jar
javac JasperReportsTest.java > javac.log 2>&1

Simple log file making me crazy (javac.log):

JasperReportsTest.java:6: unreported exception
java.lang.ClassNotFoundException; must be caught or declared to be
thrown
Class.forName("org.postgresql.Driver");
^
1 error

Obviously the file postgresql-8.1-405.jdbc3.jar is there...

Why does it say ClassNotFound if the file is there? Can anyone help me?
Thank you : )

--
Kamal


From: Jan de Visser <jdevisser(at)digitalfairway(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: I just can't use the org.postgresql.Driver class... Please help!
Date: 2006-04-05 19:02:48
Message-ID: 200604051502.48358.jdevisser@digitalfairway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Wednesday 05 April 2006 14:53, Kamal wrote:
> Simple log file making me crazy (javac.log):
>
> JasperReportsTest.java:6: unreported exception
> java.lang.ClassNotFoundException; must be caught or declared to be
> thrown
>    Class.forName("org.postgresql.Driver");
>                 ^
> 1 error
>
> Obviously the file postgresql-8.1-405.jdbc3.jar is there...
>
> Why does it say ClassNotFound if the file is there? Can anyone help me?
> Thank you : )

Well, the class is there at *compile time*. What this is telling you is that
at *runtime* Class.forName() will fail with that exception if the class is
not available *at runtime*. You need to catch the exception, like so:

try {
Class.forName( "org.postgresql.Driver" );
} catch ( ClassNotFoundException cnfe ) {
System.err.println( "driver not found!" );
}

I would recommend an introductory Java text.

jan

--
--------------------------------------------------------------
Jan de Visser                     jdevisser(at)digitalfairway(dot)com

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------