/* pour tester les classes */ import java.sql.SQLException; import java.util.HashMap; import dao.JDBC; import dao.ResultObject; import dao.SQLexecutor; /* * fonction main pour tester des commandes */ public class DAO_Test { public static void main(String[] args) throws SQLException, ClassNotFoundException { // envoie de tous les paramètres en même temps JDBC.setInfos("localhost", "mysql", "tp", "root", ""); // même chose avec envoie un par un // si un paramètre doit être modifié à la volée, faire un JDBC.setStrUlr(); après JDBC.setHost("localhost"); JDBC.setDBMS("mysql"); JDBC.setDbName("tp"); JDBC.setLogin("root"); JDBC.setPassword(""); JDBC.setStrUrl(); SQLexecutor executor = new SQLexecutor(); // SELECT ResultObject result = executor.executeQuery("SELECT * FROM acces WHERE id = ?", 1); for(HashMap row : result.getData()) // foreach sur les entrées { System.out.println("prénom: " + row.get("prenom")); //un champ d'une entrée for(HashMap.Entry one_field : row.entrySet()) // foreach sur les champs { System.out.print(one_field.getKey() + ": " + one_field.getValue() + "\n"); } } // INSERT executor.executeQuery("INSERT INTO acces (prenom, login, password, statut, age) VALUES (?, ?, ?, ?, ?)", "Dylan", "Toto", "Titi", "Etudiant", 22); // UPDATE executor.executeQuery("UPDATE acces SET statut = ? WHERE prenom = ?", "joue à fortnite", "Dylan"); // DELETE executor.executeQuery("DELETE FROM acces WHERE prenom = ?", "Dylan"); } }