Thread: jdbc example: java.lang.NoClassDefFoundError
Hello, I have been trying to access the postgresql mailing list archives online but the archives.postgresql.org server as well as a bunch of other postgresql servers appear to be down and the lists are not (yet) archived at <http://www.mail-archive.com/lists.html>. The problem I am experiencing is I have Red Hat 7.1 installed with the postgresql 7.0 stuff including postgresql-jdbc. I have set my CLASSPATH to point to /usr/lib/pgsql/jdbc7.0-1.2.jar and have also installed JDK 1.3.1 and updated the PATH variable accordingly. However I am getting the following error when trying to access a simple postgresql databse. Any ideas of what might have gone wrong? Exception in thread "main" java.lang.NoClassDefFoundError: TestPostgreSQL Thanks, Neil sample code generating the error: import java.sql.*; class TestPostgreSQL { public static void main(String arg[]) throws SQLException, ClassNotFoundException { String db_driver = "org.postgresql.Driver"; String db_site = "jdbc:postgresql:joedb"; String db_user = "joe"; String db_pass = "doe"; Class.forName(db_driver); Connection connection = DriverManager.getConnection(db_site, db_user, db_pass); Statement statement = connection.createStatement(); ResultSet resultset = statement.executeQuery("SELECT * FROM joetable"); System.out.println(resultset.getString("joe_column")); } }
Neil, Your code looks fine, how are you trying to run this? Is it in a package? Dave -----Original Message----- From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Neil Zanella Sent: November 1, 2001 11:16 PM To: PostgreSQL JDBC List Subject: [JDBC] jdbc example: java.lang.NoClassDefFoundError Hello, I have been trying to access the postgresql mailing list archives online but the archives.postgresql.org server as well as a bunch of other postgresql servers appear to be down and the lists are not (yet) archived at <http://www.mail-archive.com/lists.html>. The problem I am experiencing is I have Red Hat 7.1 installed with the postgresql 7.0 stuff including postgresql-jdbc. I have set my CLASSPATH to point to /usr/lib/pgsql/jdbc7.0-1.2.jar and have also installed JDK 1.3.1 and updated the PATH variable accordingly. However I am getting the following error when trying to access a simple postgresql databse. Any ideas of what might have gone wrong? Exception in thread "main" java.lang.NoClassDefFoundError: TestPostgreSQL Thanks, Neil sample code generating the error: import java.sql.*; class TestPostgreSQL { public static void main(String arg[]) throws SQLException, ClassNotFoundException { String db_driver = "org.postgresql.Driver"; String db_site = "jdbc:postgresql:joedb"; String db_user = "joe"; String db_pass = "doe"; Class.forName(db_driver); Connection connection = DriverManager.getConnection(db_site, db_user, db_pass); Statement statement = connection.createStatement(); ResultSet resultset = statement.executeQuery("SELECT * FROM joetable"); System.out.println(resultset.getString("joe_column")); } } ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
Neil- I should have looked more closely at your message- It appears that the message is telling you that it can't find your test class. This could be as simple as the current directory (.) not being in the class path. What does the path look like? - Nick -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/
Neil- The code looks pretty good to me. Try looking here for a couple of ideas about what can cause this error: http://www.fankhausers.com/postgresql/jdbc/#classnotfound -Nick -------------------------------------------------------------------------- Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax 1.765.962.9788 Ray Ontko & Co. Software Consulting Services http://www.ontko.com/ > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Neil Zanella > Sent: Thursday, November 01, 2001 11:16 PM > To: PostgreSQL JDBC List > Subject: [JDBC] jdbc example: java.lang.NoClassDefFoundError > > > > Hello, > > I have been trying to access the postgresql mailing list archives online > but the archives.postgresql.org server as well as a bunch of other > postgresql servers appear to be down and the lists are not (yet) > archived at <http://www.mail-archive.com/lists.html>. > > The problem I am experiencing is I have Red Hat 7.1 installed with the > postgresql 7.0 stuff including postgresql-jdbc. I have set my CLASSPATH > to point to /usr/lib/pgsql/jdbc7.0-1.2.jar and have also installed JDK > 1.3.1 and updated the PATH variable accordingly. However I am getting > the following error when trying to access a simple postgresql databse. > Any ideas of what might have gone wrong? > > Exception in thread "main" java.lang.NoClassDefFoundError: TestPostgreSQL > > Thanks, > > Neil > > sample code generating the error: > > import java.sql.*; > > class TestPostgreSQL { > public static void main(String arg[]) throws SQLException, > ClassNotFoundException { > > String db_driver = "org.postgresql.Driver"; > String db_site = "jdbc:postgresql:joedb"; > String db_user = "joe"; > String db_pass = "doe"; > > Class.forName(db_driver); > Connection connection = DriverManager.getConnection(db_site, db_user, > db_pass); > Statement statement = connection.createStatement(); > ResultSet resultset = statement.executeQuery("SELECT * FROM > joetable"); > System.out.println(resultset.getString("joe_column")); > > } > } > > > > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >
you need to have resultset.next() before using getString() ResultSet resultset = statement.executeQuery("SELECT * FROM joetable"); while (resultset.next()) { System.out.println(resultset.getString("joe_column")); } Jayesh > -----Original Message----- > From: Nick Fankhauser [SMTP:nickf@ontko.com] > Sent: Monday, November 05, 2001 6:59 AM > To: Neil Zanella; PostgreSQL JDBC List > Subject: Re: [JDBC] jdbc example: java.lang.NoClassDefFoundError > > Neil- > > The code looks pretty good to me. Try looking here for a couple of > ideas > about what can cause this error: > > http://www.fankhausers.com/postgresql/jdbc/#classnotfound > > -Nick > > ---------------------------------------------------------------------- > ---- > Nick Fankhauser nickf@ontko.com Phone 1.765.935.4283 Fax > 1.765.962.9788 > Ray Ontko & Co. Software Consulting Services > http://www.ontko.com/ > > > -----Original Message----- > > From: pgsql-jdbc-owner@postgresql.org > > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Neil Zanella > > Sent: Thursday, November 01, 2001 11:16 PM > > To: PostgreSQL JDBC List > > Subject: [JDBC] jdbc example: java.lang.NoClassDefFoundError > > > > > > > > Hello, > > > > I have been trying to access the postgresql mailing list archives > online > > but the archives.postgresql.org server as well as a bunch of other > > postgresql servers appear to be down and the lists are not (yet) > > archived at <http://www.mail-archive.com/lists.html>. > > > > The problem I am experiencing is I have Red Hat 7.1 installed with > the > > postgresql 7.0 stuff including postgresql-jdbc. I have set my > CLASSPATH > > to point to /usr/lib/pgsql/jdbc7.0-1.2.jar and have also installed > JDK > > 1.3.1 and updated the PATH variable accordingly. However I am > getting > > the following error when trying to access a simple postgresql > databse. > > Any ideas of what might have gone wrong? > > > > Exception in thread "main" java.lang.NoClassDefFoundError: > TestPostgreSQL > > > > Thanks, > > > > Neil > > > > sample code generating the error: > > > > import java.sql.*; > > > > class TestPostgreSQL { > > public static void main(String arg[]) throws SQLException, > > ClassNotFoundException { > > > > String db_driver = "org.postgresql.Driver"; > > String db_site = "jdbc:postgresql:joedb"; > > String db_user = "joe"; > > String db_pass = "doe"; > > > > Class.forName(db_driver); > > Connection connection = DriverManager.getConnection(db_site, > db_user, > > db_pass); > > Statement statement = connection.createStatement(); > > ResultSet resultset = statement.executeQuery("SELECT * FROM > > joetable"); > > System.out.println(resultset.getString("joe_column")); > > > > } > > } > > > > > > > > > > ---------------------------(end of > broadcast)--------------------------- > > TIP 2: you can get off all lists at once with the unregister command > > (send "unregister YourEmailAddressHere" to > majordomo@postgresql.org) > > > > > ---------------------------(end of > broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html