début bdd
This commit is contained in:
parent
a84a1f22ad
commit
cc25a779ab
4 changed files with 93 additions and 3 deletions
|
@ -1,10 +1,15 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-14">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/basti/eclipse/mysql-connector-java-8.0.22/mysql-connector-java-8.0.22/mysql-connector-java-8.0.22.jar">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="module" value="true"/>
|
<attribute name="module" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" path="src"/>
|
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
43
Projet_POO/src/bdd/Liaison.java
Normal file
43
Projet_POO/src/bdd/Liaison.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
module projet_POO {
|
module projet_POO {
|
||||||
requires java.desktop;
|
requires java.desktop;
|
||||||
|
requires java.sql;
|
||||||
|
requires mysql.connector.java;
|
||||||
}
|
}
|
|
@ -7,6 +7,7 @@ import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import bdd.Liaison;
|
||||||
import clavardage.gestionnaireClavardage;
|
import clavardage.gestionnaireClavardage;
|
||||||
import liste.GestionnaireListeUtilisateur;
|
import liste.GestionnaireListeUtilisateur;
|
||||||
import liste.TypeListeUtilisateur;
|
import liste.TypeListeUtilisateur;
|
||||||
|
@ -24,9 +25,14 @@ import java.awt.event.ActionListener;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.awt.event.KeyAdapter;
|
import java.awt.event.KeyAdapter;
|
||||||
import java.awt.event.KeyEvent;
|
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.
|
// Teste la validité des champs.
|
||||||
public void enter() {
|
public void enter2() {
|
||||||
String id = idField.getText();
|
String id = idField.getText();
|
||||||
String pwd = passwordField.getText();
|
String pwd = passwordField.getText();
|
||||||
|
|
||||||
|
@ -231,4 +237,38 @@ 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue