Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Comment gérer les Exceptions enchaînés en JDBC


{filelink=893}

 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class JDBCException {
  static Connection conn;
 
  public static void main(String[] args) {
    String driver = "com.mysql.jdbc.Driver";
    String DATABASE_URL = "jdbc:mysql://localhost:3306/Etudiants";
    try {
      Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
      e.printStackTrace();
    }
    try {
      conn = DriverManager.getConnection(DATABASE_URL);
      Statement stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT * FROM Notes");
      rs.next();
      rs.close();
    } catch (SQLException sx) {
      for (Throwable e : sx) {
        System.err.println("Erreur:  " + e);
      }
    }
  }
}