diff --git a/Projet_POO/.classpath b/Projet_POO/.classpath index 9394050..4bfc173 100644 --- a/Projet_POO/.classpath +++ b/Projet_POO/.classpath @@ -1,10 +1,15 @@ - + + + + + + + - diff --git a/Projet_POO/src/bdd/Liaison.java b/Projet_POO/src/bdd/Liaison.java new file mode 100644 index 0000000..ab06a27 --- /dev/null +++ b/Projet_POO/src/bdd/Liaison.java @@ -0,0 +1,43 @@ +package bdd; + +import java.sql.Connection; +import java.sql.SQLException; + +import com.mysql.cj.jdbc.MysqlDataSource; + + +public class Liaison { + + private static String username = "tp_servlet_005"; + private static String password = "eGhuu1hu"; + + private static String serverName = "srv-bdens.insa-toulouse.fr"; + private static Integer portNumber = 3306; + private static String bddNom = "tp_servlet_005"; + + public static Connection getConnection() { + + Connection con = null; + + MysqlDataSource dataSource = new MysqlDataSource(); + + dataSource.setServerName(serverName); + dataSource.setUser(username); + dataSource.setPassword(password); + dataSource.setDatabaseName(bddNom); + dataSource.setPortNumber(portNumber); + + + try { + con = dataSource.getConnection(); + + } catch (SQLException e) { + e.printStackTrace(); + } + + + + return con; + } + +} diff --git a/Projet_POO/src/module-info.java b/Projet_POO/src/module-info.java index 485fddc..fbd19e3 100644 --- a/Projet_POO/src/module-info.java +++ b/Projet_POO/src/module-info.java @@ -1,3 +1,5 @@ module projet_POO { requires java.desktop; + requires java.sql; + requires mysql.connector.java; } \ No newline at end of file diff --git a/Projet_POO/src/ui/Login_RegisterUI.java b/Projet_POO/src/ui/Login_RegisterUI.java index e794f84..37907c8 100644 --- a/Projet_POO/src/ui/Login_RegisterUI.java +++ b/Projet_POO/src/ui/Login_RegisterUI.java @@ -7,6 +7,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; +import bdd.Liaison; import clavardage.gestionnaireClavardage; import liste.GestionnaireListeUtilisateur; import liste.TypeListeUtilisateur; @@ -24,9 +25,14 @@ import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; + +import java.sql.ResultSet; +import java.sql.SQLException; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.sql.Connection; +import java.sql.PreparedStatement; @@ -202,7 +208,7 @@ public class Login_RegisterUI extends JFrame implements Runnable{ */ // Teste la validité des champs. - public void enter() { + public void enter2() { String id = idField.getText(); String pwd = passwordField.getText(); @@ -230,5 +236,39 @@ public class Login_RegisterUI extends JFrame implements Runnable{ } } + + public void enter() { + String id = idField.getText(); + String pwd = passwordField.getText(); + + PreparedStatement st; + ResultSet rs; + + String query = "SELECT * FROM user WHERE id = ? AND pwd = ?"; + + try { + Connection con = Liaison.getConnection(); + + st = con.prepareStatement(query); + //System.out.println("la"); + st.setString(1, id); + st.setString(2, pwd); + + rs = st.executeQuery(); + + if(rs.next()) { + System.out.println("BDD SUCCESS"); + } + else { + System.out.println("BDD FAIL"); + } + + + } catch (SQLException e) { + e.printStackTrace(); + } + + + } }