String Sql = "select * from LoginPwd where Name= "+ " ' "+jTextField.getText()+ " ' ";
ResultSet rs = st.executeQuery(Sql);
if (rs.next())
{
while(rs.next())
{
if (jTextField.getText().equals(rs.getString( "Name ").trim()) && jTextField1.getText().equals(rs.getString( "Password ").trim()))
{
JOptionPane.showMessageDialog(null, "welcome ");
break;
}
else
{
JOptionPane.showMessageDialog(null, "wrong account/password ");
break;
}
}
}
else
{
JOptionPane.showMessageDialog(null, "wrong account/password ");
}
我输入错误的用户名的时候,程序能够提示错误,但是当我输入正确的用户名时,程序却一点反应都没有,请问一下是什么原因
------解决方案--------------------
String Sql = "select * from LoginPwd where Name= "+ " ' "+jTextField.getText()+ " ' ";
ResultSet rs = st.executeQuery(Sql);
if (rs != null) {//判断有没有记录存在,判断它是否是空就可以了.
while(rs.next()) {
if (jTextField.getText().equals(rs.getString( "Name ").trim())
&& jTextField1.getText().equals(rs.getString( "Password ").trim())){
JOptionPane.showMessageDialog(null, "welcome ");
break;
} else {
JOptionPane.showMessageDialog(null, "wrong account/password ");
break;
}
}
} else {
JOptionPane.showMessageDialog(null, "wrong account/password ");
}
----------------------
附加一点,这位兄弟的编程风格不太好.看看我改的这种风格,看起来比较舒服,我刚工作的时候写的程序跟你写的差不多,在多次被领导的漫骂之后,才有点起色.