Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.univ_amu.iut;
- import java.sql.*;
- import java.util.HashSet;
- import java.util.Set;
- public class testAsso2 {
- private static Set<Module> stockModule= new HashSet<>();
- private static Set<Etudiant> stockEtudiant= new HashSet<>();
- static final String CONNECT_URL = "jdbc:mysql://mysql-sebouz.alwaysdata.net:3306/sebouz_database";
- static final String LOGIN = "sebouz";
- static final String PASSWORD = "123456";
- // La requete de test
- static final String req1 = "SELECT * " +
- "FROM ETUDIANT " ;
- static final String req2 = "SELECT * " +
- "FROM MODULE ";
- //static final String req3 = "SELECT * " +
- // "FROM NOTATION ";
- public static void main(String[] args) throws SQLException {
- // Objet materialisant la connexion a la base de donnees
- Connection conn = null;
- try {
- // Connexion a la base
- System.out.println("Connexion a " + CONNECT_URL);
- conn = DriverManager.getConnection(CONNECT_URL,LOGIN,PASSWORD);
- System.out.println("Connecte\n");
- // Creation d'une instruction SQL
- Statement stmt = conn.createStatement();
- // Execution de la requete
- System.out.println("Execution de la requete : " + req1 );
- ResultSet rset1 = stmt.executeQuery(req1);
- // Affichage du resultat
- while (rset1.next()){
- 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")));
- }
- System.out.println("Execution de la requete : " + req2 );
- ResultSet rset2 = stmt.executeQuery(req2);
- // Affichage du resultat
- while (rset2.next()){
- 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")));
- }
- // Fermeture de l'instruction (liberation des ressources)
- stmt.close();
- System.out.println("\nOk.\n");
- } catch (SQLException e) {
- e.printStackTrace();// Arggg!!!
- System.out.println(e.getMessage() + "\n");
- } finally {
- if (conn != null) {
- // Deconnexion de la base de donnees
- conn.close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement