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