0
我是新學生與Java,我試圖做一個應用程序,看看用戶名和密碼是否存在,所以我寫了這段代碼,並在主類我有這種方法和看看是否=真或假。while循環與mysql java數據庫
我試圖把System.out.print語句放在while循環中,並沒有顯示出來,這意味着while循環不起作用。
public void checkUserName(String username,String password) throws SQLException, ClassNotFoundException
{
openconnection();
String query ="SELECT * FROM hema.employee";
Statement stm=(Statement) con.createStatement();
ResultSet rs;
rs = stm.executeQuery(query);
while(rs.next()){
String un,pass;
un=rs.getString("UserName");
pass=rs.getString("PassWord");
System.out.println("hi your answer is "+ a);
if(un==username&&pass==password){
System.out.println("if Works");
a=true;
break;
}
}
}
我試圖把System.out.print語句放在while循環中,並沒有顯示出來,這意味着while循環不起作用。 – 2014-10-05 15:19:57
那麼你的數據庫實際上有'hema.employee'中的內容嗎?並沒有拋出SQLException?! – FAS 2014-10-05 15:22:44
其實現在它的作品現在謝謝你...但現在新問題 現在,如果a = true該應用程序運行良好,但如果a = false它給我錯誤 – 2014-10-05 15:24:58