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
| import java.sql.*;
public class Authentif {
public static int Authentif(String login1, String passwd1) {
Connection c = null;
int a = 10;
PreparedStatement ps = null;
ResultSet res = null;
try {
String query = ("select * from chateurs where login="+login1+" and password="+passwd1+";"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:Odbc:EtudiantDB");
ps = c.prepareStatement(query);
res = ps.executeQuery();
} catch (ClassNotFoundException e) {
e.getStackTrace();
}
catch (SQLException e) {
e.getStackTrace();
}
if (res == null)
a = 1;
else
a = 0;
return a;
}
public static void main(String[] args) {
String login = "user1";
String password = "user1";
System.out.println(Authentif(login, password));
}
} |
Partager