summaryrefslogtreecommitdiff
path: root/src/DAO_Test.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/DAO_Test.java')
-rw-r--r--src/DAO_Test.java38
1 files changed, 38 insertions, 0 deletions
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 @@
1/* pour tester les classes */
2
3import java.sql.SQLException;
4import java.util.HashMap;
5import dao.JDBC;
6import dao.ResultObject;
7import dao.SQLexecutor;
8
9public class DAO_Test
10{
11 public static void main(String[] args) throws SQLException, ClassNotFoundException
12 {
13 JDBC.setInfos("localhost", "mysql", "tp", "root", "");
14 SQLexecutor executor = new SQLexecutor();
15
16 // SELECT
17 ResultObject result = executor.executeQuery("SELECT * FROM acces WHERE id = ?", 1);
18 for(HashMap<String, Object> row : result.getData())
19 {
20 System.out.println("prenom: " + row.get("prenom")); // une entrée
21
22 // foreach sur toutes les entrées
23 for(HashMap.Entry<String, Object> one_field : row.entrySet())
24 {
25 System.out.print(one_field.getKey() + ": " + one_field.getValue() + "\n");
26 }
27 }
28
29 // INSERT
30 executor.executeQuery("INSERT INTO acces (prenom, login, password, statut, age) VALUES (?, ?, ?, ?, ?)", "Dylan", "Toto", "Titi", "Etudiant", 22);
31
32 // UPDATE
33 executor.executeQuery("UPDATE acces SET statut = ? WHERE prenom = ?", "joue à fortnite", "Dylan");
34
35 // DELETE
36 executor.executeQuery("DELETE FROM acces WHERE prenom = ?", "Dylan");
37 }
38}