import java.sql.*;

public class Connect6 {
  public static void main(String args[]) {
    try {
      Class.forName("com.mysql.jdbc.Driver");
    } catch(java.lang.ClassNotFoundException e) {
      System.err.print("ClassNotFoundException: ");
      System.err.println(e.getMessage());
    }    
    try {
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost/nosamisleschiens", "toto", "secretoto");
	    Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
      ResultSet.CONCUR_READ_ONLY);
      // createStatement() par defaut : ResultSet.TYPE_FORWARD_ONLY
      String query = "SELECT * FROM chien ORDER BY nombrePuces";
      System.out.println("query : " +query);      
      ResultSet rs = st.executeQuery(query);
      rs.last();
      int nombreLignes = rs.getRow();
      System.out.println("Ce ResultSet contient "+nombreLignes+" lignes.");
      do
        System.out.println("nom : "+rs.getString("nom")+" nombre de puces = "
                            +rs.getString("nombrePuces"));
      while (rs.previous());
      rs.close();
      con.close();      
    } catch(SQLException ex) {
      System.err.println("SQLException: " + ex.getMessage());
    }
  }
}

