pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedI just can't use the org.postgresql.Driver class... Please help!
4+ messages / 4 participants
[nested] [flat]
* I just can't use the org.postgresql.Driver class... Please help!
@ 2006-04-05 18:53 Kamal <kalotus@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Kamal @ 2006-04-05 18:53 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: I just can't use the org.postgresql.Driver class... Please help!
@ 2006-04-05 19:02 Jan de Visser <jdevisser@digitalfairway.com>
parent: Kamal <kalotus@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Jan de Visser @ 2006-04-05 19:02 UTC (permalink / raw)
To: 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@digitalfairway.com
Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: I just can't use the org.postgresql.Driver class... Please help!
@ 2006-04-05 21:35 Guy Rouillier <guyr@masergy.com>
0 siblings, 1 reply; 4+ messages in thread
From: Guy Rouillier @ 2006-04-05 21:35 UTC (permalink / raw)
To: pgsql-jdbc
Kamal wrote:
> 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 : )
Try providing it with a path to the jar file instead of just the jar
file name: ./postgresql-8.1-405.jdbc3.jar. Might as well add the
current directory to that so it doesn't complain about the source file
you're trying to compile.
--
Guy Rouillier
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: I just can't use the org.postgresql.Driver class... Please help!
@ 2006-04-11 01:51 Andres Olarte <olarte.andres@gmail.com>
parent: Guy Rouillier <guyr@masergy.com>
0 siblings, 0 replies; 4+ messages in thread
From: Andres Olarte @ 2006-04-11 01:51 UTC (permalink / raw)
To: pgsql-jdbc
You must catch an Exception that *might* be thrown, in this case it's
ClassNotFoundException.
Change:
public static void main(String[] args)
{
Class.forName("org.postgresql.Driver");
}
to
public static void main(String[] args)
{
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e ){
}
}
This way it'll compile. This has nothing to do with JDBC, this is
basic Java stuff.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2006-04-11 01:51 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-05 18:53 I just can't use the org.postgresql.Driver class... Please help! Kamal <kalotus@gmail.com>
2006-04-05 19:02 ` Jan de Visser <jdevisser@digitalfairway.com>
2006-04-05 21:35 Re: I just can't use the org.postgresql.Driver class... Please help! Guy Rouillier <guyr@masergy.com>
2006-04-11 01:51 ` Andres Olarte <olarte.andres@gmail.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