Guest User

Untitled

a guest
Jan 31st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. String url = "jdbc:mysql://localhost:3306/supsales";
  2. String root = "root";
  3. String password= "";
  4. Connection connexion = null;
  5.  
  6. try {
  7.     connexion = DriverManager.getConnection(url, root , password);
  8.     /* Ici, nous placerons nos requêtes vers la BDD */
  9.  
  10.     statement = connexion.createStatement();
  11.    
  12.     resultat = statement.executeQuery( "SELECT pseudo, email, nom, prenom FROM utilisateur;" );
  13. } catch ( SQLException e ) {
  14.     messages.add("Erreur lors de la connexion " + e);
  15. } finally {
  16.             if ( resultat != null ) {
  17.             try {
  18.                 resultat.close();
  19.             } catch ( SQLException ignore ) {
  20.             }
  21.         }
  22.  
  23.         messages.add( "Fermeture de l'objet Statement." );
  24.  
  25.         if ( statement != null ) {
  26.             try {
  27.                 statement.close();
  28.             } catch ( SQLException ignore ) {
  29.             }
  30.         }
  31.         messages.add( "Fermeture de l'objet Connection." );
  32.         if ( connexion != null ) {
  33.             try {
  34.                 connexion.close();
  35.             } catch ( SQLException ignore ) {
  36.             }
  37.         }
  38.     return messages;
  39. }
Add Comment
Please, Sign In to add comment