1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
private void buttonSeConnecterActionPerformed(java.awt.event.ActionEvent evt) {
PreparedStatement test = null;
String login = textFieldIdentifiant.getText();
String mdp = passwordFieldMotDePasse.getText();
ResultSet rs = null;
String url = "jdbc:mysql://localhost/...";
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";// connexion driver jdbc
String user = "root";
String password = "...";
try {
Class.forName(driver);
try (Connection connection = (Connection) DriverManager.getConnection(url, user, password)) {// connexion avec la bdd
String sql = "SELECT login FROM UTILISATEUR WHERE login= ? AND mdp = ?";
test = connection.prepareStatement(sql);
test.setString(1, login);
test.setString(2, mdp);
rs = test.executeQuery();
if (rs == null) {
System.out.println("Echec de la connexion");
} else {
System.out.println("Connexion réussie");
setVisible(false);// fermer la frame courante auth
new accueil().setVisible(true);// ouvre la frame accueil
}
}
} catch (ClassNotFoundException | SQLException cnfe) {
System.err.println(cnfe);
}
} |
Partager