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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| try {
Class.forName("com.mysql.cj.jdbc.Driver");
// Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("mysql cj");
e1.printStackTrace();
}
Connection connection = null;
try {
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/germinal?serverTimezone=UTC","root","motdepasse");
String sql = "SELECT idmembre FROM membre WHERE email= ? and motpasse= ?";
// Statement statement = connection.createStatement();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT idmembre FROM membre WHERE email= ? and motpasse= ?");
preparedStatement.setString(1,mail);
preparedStatement.setString(2,motPasse);
/* Exécution d'une requête de lecture */
ResultSet resultat = preparedStatement.executeQuery();
/* Récupération des données du résultat de la requête de lecture */
if ( resultat.next()) {
// String emailUtilisateur = resultat.getString( "email" );
// String motDePasseUtilisateur = resultat.getString( "motpasse" );
res="success";
response.setContentType("text/html");
response.getWriter().write(res);
} else
{res="echec";
response.setContentType("text/html");
response.getWriter().write(res);}
}
catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
return;
}
if (connection != null) {
System.out.println("You made it, take control your database now!");
} else {
System.out.println("Failed to make connection!");
}
} |