summaryrefslogtreecommitdiff
path: root/src/DAO_Test.java
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2025-02-15 15:25:40 +0100
committerpolo <ordipolo@gmx.fr>2025-02-15 15:25:40 +0100
commit30c38f78018c160fdeb44175e4ef97f0c2868b37 (patch)
treeb785851b95bac67305212d9da076fcdb62872d26 /src/DAO_Test.java
parentefed27a703022ecb366a301340f5fcbb8135a2fd (diff)
downloadJDBC-30c38f78018c160fdeb44175e4ef97f0c2868b37.zip
release candidate 3
Diffstat (limited to 'src/DAO_Test.java')
-rw-r--r--src/DAO_Test.java51
1 files changed, 0 insertions, 51 deletions
diff --git a/src/DAO_Test.java b/src/DAO_Test.java
deleted file mode 100644
index 673f2b7..0000000
--- a/src/DAO_Test.java
+++ /dev/null
@@ -1,51 +0,0 @@
1/* pour tester les classes */
2
3import java.sql.SQLException;
4import java.util.HashMap;
5import dao.JDBC;
6import dao.ResultObject;
7import dao.SQLexecutor;
8
9/*
10 * fonction main pour tester des commandes
11 */
12public class DAO_Test
13{
14 public static void main(String[] args) throws SQLException, ClassNotFoundException
15 {
16 // envoie de tous les paramètres en même temps
17 JDBC.setInfos("localhost", "mysql", "tp", "root", "");
18
19 // même chose avec envoie un par un
20 // si un paramètre doit être modifié à la volée, faire un JDBC.setStrUlr(); après
21 JDBC.setHost("localhost");
22 JDBC.setDBMS("mysql");
23 JDBC.setDbName("tp");
24 JDBC.setLogin("root");
25 JDBC.setPassword("");
26 JDBC.setStrUrl();
27
28 SQLexecutor executor = new SQLexecutor();
29
30 // SELECT
31 ResultObject result = executor.executeQuery("SELECT * FROM acces WHERE id = ?", 1);
32 for(HashMap<String, Object> row : result.getData()) // foreach sur les entrées
33 {
34 System.out.println("prénom: " + row.get("prenom")); //un champ d'une entrée
35
36 for(HashMap.Entry<String, Object> one_field : row.entrySet()) // foreach sur les champs
37 {
38 System.out.print(one_field.getKey() + ": " + one_field.getValue() + "\n");
39 }
40 }
41
42 // INSERT
43 executor.executeQuery("INSERT INTO acces (prenom, login, password, statut, age) VALUES (?, ?, ?, ?, ?)", "Dylan", "Toto", "Titi", "Etudiant", 22);
44
45 // UPDATE
46 executor.executeQuery("UPDATE acces SET statut = ? WHERE prenom = ?", "joue à fortnite", "Dylan");
47
48 // DELETE
49 executor.executeQuery("DELETE FROM acces WHERE prenom = ?", "Dylan");
50 }
51}