Lecture Videos
  1  import java.sql.*;
  2  
  3  public class SimpleJdbc {
  4    public static void main(String[] args)
  5        throws SQLException, ClassNotFoundException {
  6      // Load the JDBC driver
  7      Class.forName("com.mysql.jdbc.Driver");
  8      System.out.println("Driver loaded");
  9  
 10      // Connect to a database
 11      Connection connection = DriverManager.getConnection
 12        ("jdbc:mysql://localhost/javabook" , "scott", "tiger");
 13      System.out.println("Database connected");
 14  
 15      // Create a statement
 16      Statement statement = connection.createStatement();
 17  
 18      // Execute a statement
 19      ResultSet resultSet = statement.executeQuery
 20        ("select firstName, mi, lastName from Student where lastName "
 21          + " = 'Smith'");
 22  
 23      // Iterate through the result and print the student names
 24      while (resultSet.next())
 25        System.out.println(resultSet.getString(1) + "\t" +
 26          resultSet.getString(2) + "\t" + resultSet.getString(3));
 27  
 28      // Close the connection
 29      connection.close();
 30    }
 31  }