select password from user where id = ?;取到password后和输入的password比一下不就可以了吗 String flag = "0"; if("password(DB)".equals("password(画面)"){ flag = "1" } flag为0时不存在该用户,为1时存在。 其他的事情就是从数据库取值拉。
上面那个你还要判断,DB的password是不是空,要不会出现异常
function boolean checkpwd(id string, pwd String){boolean result = false;//驱动程序名 String driverName="com.mysql.jdbc.Driver"; //数据库用户名 String userName="cl41"; //密码 String userPasswd="123456"; //数据库名 String dbName="db";//联结字符串 String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd; Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection connection=DriverManager.getConnection(url); Statement statement = connection.createStatement();String sql="SELECT userid, password FROM login where userid="+id; ResultSet rs = statement.executeQuery(sql); if (rs.next()) { if (out.print(rs.getString(1) = pwd ) result = true; } }
from user
where id = ?;取到password后和输入的password比一下不就可以了吗
String flag = "0";
if("password(DB)".equals("password(画面)"){
flag = "1"
}
flag为0时不存在该用户,为1时存在。
其他的事情就是从数据库取值拉。
String driverName="com.mysql.jdbc.Driver";
//数据库用户名
String userName="cl41";
//密码
String userPasswd="123456";
//数据库名
String dbName="db";//联结字符串
String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();String sql="SELECT userid, password FROM login where userid="+id;
ResultSet rs = statement.executeQuery(sql);
if (rs.next()) {
if (out.print(rs.getString(1) = pwd ) result = true;
}
}