MAJ modele user
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user