[CLUE-Tech] Java, PostgreSQL and JDBC help needed
Jeffery Cann
fabian at jefferycann.com
Thu Jun 5 22:20:08 MDT 2003
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
More information about the clue-tech
mailing list