From 749ecc302159099ae3a23fd6b27dad74cbc607c7 Mon Sep 17 00:00:00 2001 From: yolou Date: Thu, 23 Oct 2025 23:50:43 +0200 Subject: [PATCH] MAJ modele user --- src/fr/iutfbleau/papillon/BaseDeDonnees.java | 2 +- src/fr/iutfbleau/papillon/UtilisateurBD.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/fr/iutfbleau/papillon/BaseDeDonnees.java b/src/fr/iutfbleau/papillon/BaseDeDonnees.java index 439ff35..c817ea5 100644 --- a/src/fr/iutfbleau/papillon/BaseDeDonnees.java +++ b/src/fr/iutfbleau/papillon/BaseDeDonnees.java @@ -6,7 +6,7 @@ public class BaseDeDonnees { private static final String USER = "val"; private static final String PASS = "vali"; - public static java.sql.Connection getConnexion() throws java.sql.SQLException { + public static java.sql.Connection getConnexion() throws SQLException { try { Class.forName("org.mariadb.jdbc.Driver"); } catch (ClassNotFoundException e) { diff --git a/src/fr/iutfbleau/papillon/UtilisateurBD.java b/src/fr/iutfbleau/papillon/UtilisateurBD.java index 30f7cd9..ca33a4e 100644 --- a/src/fr/iutfbleau/papillon/UtilisateurBD.java +++ b/src/fr/iutfbleau/papillon/UtilisateurBD.java @@ -2,7 +2,7 @@ import java.sql.*; public class UtilisateurBD { - public static int getUserIdByKey(String cle) throws java.sql.SQLException { + public static int getUserIdByKey(String cle) throws SQLException { String sql = "SELECT id FROM utilisateur WHERE cle_unique = ?"; Connection cnx = BaseDeDonnees.getConnexion(); @@ -11,7 +11,7 @@ public class UtilisateurBD { ResultSet rs = pst.executeQuery(); int id = -1; - + if (rs.next()){ id = rs.getInt("id"); } @@ -21,17 +21,19 @@ public class UtilisateurBD { return id; } - public static int creerUtilisateur(String nom, String cle) throws java.sql.SQLException { + public static int creerUtilisateur(String nom, String cle) throws SQLException { String sql = "INSERT INTO utilisateur(nom, cle_unique) VALUES (?, ?)"; - java.sql.Connection cnx = BaseDeDonnees.getConnexion(); - java.sql.PreparedStatement pst = cnx.prepareStatement(sql, java.sql.Statement.RETURN_GENERATED_KEYS); + Connection cnx = BaseDeDonnees.getConnexion(); + PreparedStatement pst = cnx.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); pst.setString(1, nom); pst.setString(2, cle); pst.executeUpdate(); int id = -1; - java.sql.ResultSet rs = pst.getGeneratedKeys(); - if (rs.next()) id = rs.getInt(1); + ResultSet rs = pst.getGeneratedKeys(); + if (rs.next()){ + id = rs.getInt(1); + } rs.close(); pst.close(); @@ -39,7 +41,7 @@ public class UtilisateurBD { return id; } - public static int getOrCreateUserId(String cle, String nomParDefaut) throws java.sql.SQLException { + public static int getOrCreateUserId(String cle, String nomParDefaut) throws SQLException { int id = getUserIdByKey(cle); if (id != -1){ return id;