Guest User

Untitled

a guest
Jun 23rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package fr.univ_aix.iut.TestJdbc;
  2.  
  3. /**
  4. * Hello world!
  5. *
  6. */
  7. //Importer les classes jdbc
  8. import java.sql.*;
  9.  
  10.  
  11. public class App {
  12.  
  13. // Chaine de connexion (constante)
  14. static String CONNECT_URL = "jdbc:mysql://localhost:3306/FloyDB";
  15. // La requête de test (constante)
  16. static final String req = "SELECT NUM_ET, NOM_ET, PRENOM_ET " +
  17. "FROM ETUDIANT " +
  18. "WHERE VILLE_ET = 'AIX-EN-PROVENCE'";
  19.  
  20. public static void main(String[] args) throws SQLException {
  21. // Objet materialisant la connexion à la base de données
  22.  
  23. try {
  24. // Création et paramétrage d'une instance OracleDataSource
  25. Connection conn = DriverManager.getConnection(CONNECT_URL, "root", "mysql");
  26.  
  27. // Creation d'une instruction
  28. Statement stmt = conn.createStatement();
  29.  
  30. // Execution de la requete
  31. System.out.println("Exécution de la requête : " + req + "\n");
  32. ResultSet rset = stmt.executeQuery(req);
  33.  
  34. // Affichage du résultat
  35. while (rset.next()){
  36. System.out.print(rset.getInt("NUM_ET") + " ");
  37. System.out.print(rset.getString("NOM_ET") + " ");
  38. System.out.println(rset.getString("PRENOM_ET"));
  39. }
  40. // Fermeture de l'instruction (libération des ressources)
  41. stmt.close();
  42. System.out.println("\nOk.\n");
  43.  
  44. } catch (Exception e) {
  45. e.printStackTrace();// Arggg!!!
  46. System.out.println(e.getMessage() + "\n");
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment