Introductory JDBC Example (MCS-270, Spring 2001)

import java.sql.*;

public class Decades {

  public static void main(String args[]){
    try{
      Class.forName("postgresql.Driver");
      Connection c = DriverManager.getConnection
        ("jdbc:postgresql://kilpinen.mcs.gac.edu/max_movies",
         "nobody", "(password disclosed in class)");
      Statement stmt = c.createStatement();
      for(int decadeStart = 1920; decadeStart < 2000; decadeStart += 10){
        System.out.println("==== Movies of the " + decadeStart + "s ====");
        ResultSet rs = stmt.executeQuery
          ("select title, year_made from movies "
           + "where year_made >= " + decadeStart
           + " and year_made < " + (decadeStart + 10));
        while(rs.next()){
          System.out.println(rs.getString(1) + " (" + rs.getInt(2) + ")");
        }
      }
    } catch(Exception e){
      System.err.println(e);
    }
  }
}