java - 一次登录不能使用多个用户
问题描述
我的 mysql 数据库中有 2 个数据库,当我输入第一行是“用户名”并且密码是“密码”时,它会相应地进行。但是当我进入第二行时,它说密码错误
这是我的代码:
public void tlogin() {
String u,p;
try {
String username,password;
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/subject_db","root","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM teacher_login");
while(rs.next()) {
System.out.println("Enter Username: ");
u =new Scanner(System.in).nextLine();
System.out.println("Enter Password: ");
p =new Scanner(System.in).nextLine();
while(!(u.equals(username = rs.getString(2))&&p.equals(password = rs.getString(3)))) {
System.out.println("Incorrect Login!");
System.out.println("Enter Username: ");
u =new Scanner(System.in).nextLine();
System.out.println("Enter Password: ");
p =new Scanner(System.in).nextLine();
}
System.out.println("Correct Login!");
TimeUnit.SECONDS.sleep(1);
thome();
}
con.close();
}
catch(Exception e) {
System.out.println(e);
}
}
解决方案
推荐阅读
- imagemagick - google colab上moviepy中的文本剪辑(imagemagick错误)
- sql - 如何从两列查询结果中删除重复的 id 对
- php - Checkbox selected or unselected after submit
- excel - 电子表格 | 计算时差
- javascript - 在函数组件中使用 useFocusEffect 的问题
- java - 从 Recyclerrview 到 Activity 的共享元素转换
- c# - 如何在控制器中最小化更新方法
- neo4j - Neo4j加载csv很长时间
- laravel - 我可以在 graphql 方案中使用打包方法吗?
- python - 如何使用 python 请求将文件上传到烧瓶应用程序