Advertisement
Guest User

Untitled

a guest
Oct 30th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. package fr.univ_amu.iut;
  2.  
  3.  
  4. import java.sql.*;
  5. import java.util.HashSet;
  6. import java.util.Set;
  7.  
  8.  
  9. public class testAsso2 {
  10. private static Set<Module> stockModule= new HashSet<>();
  11. private static Set<Etudiant> stockEtudiant= new HashSet<>();
  12.  
  13. static final String CONNECT_URL = "jdbc:mysql://mysql-sebouz.alwaysdata.net:3306/sebouz_database";
  14. static final String LOGIN = "sebouz";
  15. static final String PASSWORD = "123456";
  16. // La requete de test
  17. static final String req1 = "SELECT * " +
  18. "FROM ETUDIANT " ;
  19. static final String req2 = "SELECT * " +
  20. "FROM MODULE ";
  21. //static final String req3 = "SELECT * " +
  22. // "FROM NOTATION ";
  23. public static void main(String[] args) throws SQLException {
  24. // Objet materialisant la connexion a la base de donnees
  25. Connection conn = null;
  26. try {
  27. // Connexion a la base
  28. System.out.println("Connexion a " + CONNECT_URL);
  29. conn = DriverManager.getConnection(CONNECT_URL,LOGIN,PASSWORD);
  30. System.out.println("Connecte\n");
  31. // Creation d'une instruction SQL
  32. Statement stmt = conn.createStatement();
  33. // Execution de la requete
  34. System.out.println("Execution de la requete : " + req1 );
  35. ResultSet rset1 = stmt.executeQuery(req1);
  36. // Affichage du resultat
  37. while (rset1.next()){
  38. stockEtudiant.add(new Etudiant(rset1.getInt("NUM_ET"),rset1.getString("NOM_ET"),rset1.getString("PRENOM_ET"),rset1.getString("CP_ET"),rset1.getString("VILLE_ET"),rset1.getInt("ANNEE"),rset1.getInt("GROUPE")));
  39. }
  40. System.out.println("Execution de la requete : " + req2 );
  41. ResultSet rset2 = stmt.executeQuery(req2);
  42. // Affichage du resultat
  43. while (rset2.next()){
  44. stockModule.add(new Module(rset2.getString("CODE"), rset2.getString("LIBELLE"), rset2.getInt("H_COURS_PREV"), rset2.getInt("H_COURS_REA"),rset2.getInt("H_TP_PREV"), rset2.getInt("H_TP_REA"), rset2.getString("DISCIPLINE"),rset2.getInt("COEFF_TEST") , rset2.getInt("COEFF_CC"),rset2.getInt("RESP")));
  45. }
  46.  
  47. // Fermeture de l'instruction (liberation des ressources)
  48. stmt.close();
  49. System.out.println("\nOk.\n");
  50. } catch (SQLException e) {
  51. e.printStackTrace();// Arggg!!!
  52. System.out.println(e.getMessage() + "\n");
  53. } finally {
  54. if (conn != null) {
  55. // Deconnexion de la base de donnees
  56. conn.close();
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement