// for the PostgreSQL JDBC driver jar file see jdbc.postgres.org
// run with: java -cp <path to postgresjdbc.jar>;. -Djdbc.drivers=org.postgresql.Driver PostgreSQLDemo

import java.sql.*;

public class PostgreSQLDemo
{
   public static void main(String[] args)
   {
      try {
         // Connect to the database
         System.out.println("If Java complains about unknown DB driver add the PostgreSQL driver (jdbc.postgres.org) to the class path");
         Connection db = DriverManager.getConnection("jdbc:postgresql://mpiat0308.ag5.mpi-sb.mpg.de/unisb", "unisb1234567", "user1234@somedomain.de");

         // Run a dummy query on a
         System.out.println("Warning: the following query will fail, it is just a code demonstation!");
         Statement st = db.createStatement();
         ResultSet rs = st.executeQuery("SELECT MatrNr FROM Studenten");
         while (rs.next()) {
            System.out.println(rs.getString(1));
         }
         rs.close();
         st.close();

         // Close the database connection
         db.close();
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

