123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.ArrayList;
-
- public class ConnexionBDD
- {
- Connection connexionbdd;
- String nomBdd;
- GestionCategories gestionCategories;
- GestionReponses gestionReponses;
- GestionQuestions gestionQuestions;
-
- public ConnexionBDD(String nomBdd, int port, String ip, String login, String password)
- {
- this.nomBdd = nomBdd;
-
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- }
- catch(ClassNotFoundException e)
- {
- e.printStackTrace();
- System.exit(1);
- }
-
- try
- {
- String url = "jdbc:mysql://" + ip + ":" + port + "/" + nomBdd;
- connexionbdd = DriverManager.getConnection(url, login, password);
-
- gestionCategories = new GestionCategories(connexionbdd);
- gestionReponses = new GestionReponses(connexionbdd);
- gestionQuestions = new GestionQuestions(connexionbdd);
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- System.out.println("Erreur de conexion à la base de données");
- System.exit(1);
- }
- }
-
- //Gestion catégorie
- public ArrayList<Categorie> getListeCategorie()
- {
- gestionCategories.readCategorie();
- return gestionCategories.getListCategories();
- }
-
- public void createCategorie(String categorieName)
- {
- gestionCategories.createCategorie(categorieName);
- }
-
- public void deleteCategorie(String categorieName)
- {
- gestionCategories.deleteCategorie(categorieName);
- }
-
- public void renameCategorie(String oldCategorieName, String newCategorieName)
- {
- gestionCategories.updateCategorie(oldCategorieName, newCategorieName);
- }
-
- //Gestion réponses
- public ArrayList<Reponses> getListeReponses(String catName)
- {
- gestionReponses.readReponses(catName);
- return gestionReponses.getListReponses();
- }
-
- public void createReponses(String nomCategorie, String reponse1, String reponse2)
- {
- gestionReponses.createReponses(nomCategorie, reponse1, reponse2);
- }
-
- public void deleteReponses(String reponse1, String reponse2)
- {
- gestionReponses.deleteReponses(reponse1, reponse2);
- }
-
- public void modifyReponsesReponses(String categorie, String oldRep1, String oldRep2, String newRep1, String newRep2)
- {
- gestionReponses.updateReponsesReponses(categorie, oldRep1, oldRep2, newRep1, newRep2);
- }
-
- //Gestion questions
- public ArrayList<Question> getListeQuestions(String reponse1, String reponse2)
- {
- gestionQuestions.readQuestions(reponse1, reponse2);
- return gestionQuestions.getListeQuestions();
- }
-
- public void createQuestion(String intitule, String reponse1, String reponse2, int num_reponse)
- {
- gestionQuestions.createQuestion(intitule, reponse1, reponse2, num_reponse);
- }
- }
|