/* * This sample shows how to list some movie titles from the imdb database */ // You need to import the java.sql package to use JDBCimport java.sql.*; import java.sql.*; public class Movie1 { public static void main(String[] args) { // Connect to the database // You can put a database name before the ? in the connection URL. Connection conn = null; String url = "jdbc:mysql://sql.cs.oberlin.edu/?"; String parms = "user=alice&password=tiger&useSSL=false"; try { conn = DriverManager.getConnection(url+parms); // Create a Statement Statement stmt = conn.createStatement (); // Select data from the productions table ResultSet rset = stmt.executeQuery ("select * from imdb.productions where title like 'Land of the %' and (type='movie' or type='tvMovie' or type='tvSeries') order by title,year"); // Iterate through the result and print the movie titles int ct = 0; while (rset.next () && ct<100){ System.out.println (rset.getString("title") + " (" + rset.getString("type") + "/" + rset.getString("year") + ")"); ++ct; } // close the ResultSet if(rset != null) rset.close(); // close the connection if (conn != null) conn.close(); } catch(SQLException e) { e.printStackTrace(); } catch(Exception ee){ ee.printStackTrace(); } } }