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
|
///////////////////////////////////////////////////////////////////////////////
public String authentification(){
String ok = "";
try { Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e){
System.out.println("La classe de mon Driver n'a pas été trouvée");
e.printStackTrace();}
try {
String url1="jdbc:mysql://[host][:port]/[database]";
// ex : "jdbc:mysql://localhost:3306/DB_Test";
String userName1="...."; // nom du root
String pwd1 = "...."; // passwprd du root
conn = DriverManager.getConnection(url1, userName1, pwd1);
stmt = conn.createStatement();
String sqlselect = "SELECT * FROM authent WHERE login='"+this.login+"' and passwd='"+this.passwd+"';";
ResultSet rSet = stmt.executeQuery(sqlselect);
int existe = 0;
while(rSet.next()){ existe++; }
if(existe == 1){
ok = "envoyer";
}
conn.close();
stmt.close();
}catch (SQLException eGetConn){
eGetConn.printStackTrace();
}finally {
try {stmt.close();
} catch(SQLException eStmt){
eStmt.printStackTrace();}
try {conn.close();
} catch(SQLException eConn){
eConn.printStackTrace();}
}
return ok;
}
/////////////////////////////////////////////////////////////////////////////// |
Partager