Enterprise Java for Linux HOWTO 
Confirming Your Installation 
You are now ready to compile and run a simple JDBC application that uses PostgreSQL.  Create the following
program. 
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()); 
  } 
} 
Compile the program with the Java compiler. 
javac PostgreSQLTest.java  
If the compiler produces errors, double check the syntax and confirm your PATH and CLASSPATH. 
Run the program with the JVM. 
java PostgreSQLTest  
If the JVM produces errors, confirm your PATH and CLASSPATH. 
You should see the following output: 
Hello, from PostgreSQL!  
Congratulations, you have installed, set up an environment for, and tested a JDBC interface to PostgreSQL. 
More Information
For more information, I suggest you look into the PostgreSQL website at 
http://www.postgresql.org/
. 
Confirming Your Installation 
23






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved