我有一个SQL表中的数据保存,也从SQL表结果和测试这些数据.当我跑我的程序管理器类,一帧将显示,获得ID和密码,如果他们是正确的,其他的框架会显示.但我不知道为什么它只是测试SQL表的最后一行?我的意思是,如果我将这些文本字段设置为除了最后一行之外的其他ID和密码.它将显示数据错误(我之前为错误的数据设置了它)
经理班:
public static boolean Test(String userName, String password) {
boolean bool = false;
Statement stmt = null;
try {
stmt = conn.createStatement();
ResultSet rst = null;
rst = stmt.executeQuery("SELECT yahooId , password FROM clienttable");
while (rst.next()) {
if (rst.getString(1).equalsIgnoreCase(userName) && rst.getString(2).equalsIgnoreCase(password)) {
bool = true;
} else {
bool = false;
}
}
} catch (SQLException ex) {
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null, ex);
}
return bool;
}
Run Code Online (Sandbox Code Playgroud)
我的按钮在框架中执行操作,获取ID和密码并测试它:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
submit();
} catch (ConnectException ex) { …Run Code Online (Sandbox Code Playgroud)