Introductory JDBC Example
/* You'll need to make sure that ~wolfe/public/270/mysql.jar is in
your CLASSPATH for this to work.*/
import java.sql.*;
public class Decades {
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
// new com.mysql.jdbc.Driver();
Connection c = DriverManager.getConnection
("jdbc:mysql://mcs-jsp.gac.edu/test_movies",
"wolfe", "(password goes here)");
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);
}
}
}