1  import java.sql.*;
  2  
  3  public class FindUserTables {
  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      DatabaseMetaData dbMetaData = connection.getMetaData();
 16  
 17      ResultSet rsTables = dbMetaData.getTables(null, null, null,
 18        new String[] {"TABLE"});
 19      System.out.print("User tables: ");
 20      while (rsTables.next()) 
 21        System.out.print(rsTables.getString("TABLE_NAME") + " ");
 22  
 23      // Close the connection
 24      connection.close();
 25    }
 26  }