From d8dc2b6d0d4dbc93da853ef5a7562d6a223ee918 Mon Sep 17 00:00:00 2001 From: polo-pc-greta Date: Sat, 15 Feb 2025 11:52:51 +0100 Subject: release candidate 1 --- src/DAO_Test.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/DAO_Test.java (limited to 'src/DAO_Test.java') diff --git a/src/DAO_Test.java b/src/DAO_Test.java new file mode 100644 index 0000000..aa6a0af --- /dev/null +++ b/src/DAO_Test.java @@ -0,0 +1,38 @@ +/* pour tester les classes */ + +import java.sql.SQLException; +import java.util.HashMap; +import dao.JDBC; +import dao.ResultObject; +import dao.SQLexecutor; + +public class DAO_Test +{ + public static void main(String[] args) throws SQLException, ClassNotFoundException + { + JDBC.setInfos("localhost", "mysql", "tp", "root", ""); + SQLexecutor executor = new SQLexecutor(); + + // SELECT + ResultObject result = executor.executeQuery("SELECT * FROM acces WHERE id = ?", 1); + for(HashMap row : result.getData()) + { + System.out.println("prenom: " + row.get("prenom")); // une entrée + + // foreach sur toutes les entrées + for(HashMap.Entry one_field : row.entrySet()) + { + 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"); + } +} -- cgit v1.2.3