我对编码很陌生,所以我需要帮助。我在 netbeans 中构建了一个应用程序,该应用程序连接到一个数据库,我可以在其中存储和检索客户详细信息。我现在要做的是让用户输入登录名和密码,然后才能继续。所以在我的数据库中,我有一个名为 LoginPassword 的表,它存储(你可以猜到)用户登录名和密码。我需要帮助的是一些代码,它将用户输入的登录名和密码与我的数据库中的登录名和密码进行比较。我应该从哪里开始?
问问题
2678 次
2 回答
1
制作一张名为“用户”的表。其中包含“用户名”和“密码”
单击登录按钮后,对“用户”表进行查询以获取用户记录是否不存在。如果在登录屏幕中输入的“用户名”和“密码”相同,则导航到详细信息屏幕,否则显示失败消息。
于 2012-12-06T07:36:42.593 回答
0
String username= request.getParamaeter("username");
String passowrd= request.getParamaeter("passowrd");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection ("jdbc:mysql://localhost:3306/aeses","root","password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from loginPassword");
while (rs.next()){
if(username.equals(rs.getString("username")))
{
System.out.print("username matched");
if(username.equals(rs.getString("password")))
{
System.out.print("password matched you can redirect to home page here");
}
}
else
{
System.out.println("Date changed");
}
temp = rs.getString(1);
System.out.println("Current Max Date is ===>>>"+rs.getString(1));
}*/
}
/*catch (SQLException e) {
e.printStackTrace();
}*/
catch (Exception e) {
e.printStackTrace();
}
finally {
}
于 2012-12-06T07:40:36.743 回答