[CLUE-Tech] Java, PostgreSQL and JDBC help needed
Joseph Thomas
greywolf921 at hotmail.com
Thu Jun 5 23:12:17 MDT 2003
the driver I am trying to use is located in /usr/share/pgsql/pg73b1jdbc2.jar
This (acording to postgresql.org) is the jdbc driver to use for postgresql
jdbc.
also, to correct my code, per the advice of another person, I have tried the
line :
Class.forName("postgresql.Driver").newInstance();
and I also tried:
Class.forName("org.postgresql.Driver").newInstance();
here is the command line I am typing and the response:
[joe at localhost JDBCTest]# java PostgreSQLTest
Exception in thread "main" java.lang.NoClassDefFoundError:
PostgreSQLTest
----Original Message Follows----
From: Jeffery Cann <fabian at jefferycann.com>
Reply-To: clue-tech at clue.denver.co.us
To: clue-tech at clue.denver.co.us
Subject: Re: [CLUE-Tech] Java, PostgreSQL and JDBC help needed
Date: Thu, 5 Jun 2003 22:20:08 -0600
Since you didn't tell us which class was not found, it's hard to say if your
problem is your CLASSPATH or not.
Post the command line that you are using to run your program. My guess is
that since you have this PostgreSQLtest class in package JDBCTest, you
forgot
to do this:
$ java JDBCTest.PostgreSQLTest
Also, make sure your path to this package is in your CLASSPATH. A simpler
approach is to gid rid of the package statement in your .java file and then
do:
$ java PostgreSQLTest
Jeff
On Thursday 05 June 2003 10:02 pm, Joseph Thomas wrote:
> Hello,
>
> I need some help here. I am a student and dont know alot about Linux yet.
I
> am trying to be able to program in Java in linux.
> I am running Red Hat 9, PostgreSQL 7.3.2
> I have the J2SDK 1.3.1 installed and working.
> I have set up a database in PostgreSQL and am able to run queries on it.
> The trouble I am having is that I cannot get my program to connect to the
> DB, I am recieving a Class not found exception.
> I have the .jar for pgsql in my CLASSPATH set in my $HOME/.bash_profile
and
> it seems to be working.
> Here is my code I am using:
>
> package JDBCTest;
> import java.sql.*;
>
> class PostgreSQLTest
> {
> public static void main (String[] args)
> {
> try
> {
> Driver driver = (Driver)
> Class.forName("postgresql.Driver").newInstance();
>
> DriverManager.registerDriver(driver);
>
> String url = "jdbc:postgresql:javatest";
> Connection con = DriverManager.getConnection(url, "postgres", "");
> Statement stm = con.createStatement();
>
> stm.setQueryTimeout(10);
> ResultSet rs = stm.executeQuery("select col1 from test");
>
> rs.next();
>
> System.out.println(rs.getString(1));
>
> } catch (SQLException e) {
>
> System.out.println("Exception!");
> System.out.println(e.toString());
> }catch (ClassNotFoundException e) {
>
> System.out.println("Exception!");
> System.out.println(e.toString());
> }catch (InstantiationException e) {
>
> System.out.println("Exception!");
> System.out.println(e.toString());
> } catch (IllegalAccessException e) {
>
> System.out.println("Exception!");
> System.out.println(e.toString());
> }
> }//main()
> } //class
>
> _________________________________________________________________
> MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.
> http://join.msn.com/?page=features/virus
>
> _______________________________________________
> CLUE-Tech mailing list
> CLUE-Tech at clue.denver.co.us
> http://clue.denver.co.us/mailman/listinfo/clue-tech
--
"Keep yourselves far from every form of exaggerated nationalism, racism and
intolerance."
-- Pope John Paul II
_______________________________________________
CLUE-Tech mailing list
CLUE-Tech at clue.denver.co.us
http://clue.denver.co.us/mailman/listinfo/clue-tech
_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the clue-tech
mailing list