[CLUE-Tech] Java, PostgreSQL and JDBC help needed
    Joseph Thomas 
    greywolf921 at hotmail.com
       
    Thu Jun  5 22:02:46 MDT 2003
    
    
  
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
    
    
More information about the clue-tech
mailing list