大家帮帮看看这段代码的是不是有逻辑问题
String Sql = "select * from LoginPwd where Name= "+ " ' "+jTextField.getText()+ " ' ";
ResultSet rs = st.executeQuery(Sql);
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;
}
}
我数据库有两个账号kaka,edison密码都是123
我输进去会不会有问题,另外我随便输入字符没有反应,请问一下是什么原因.!
------解决方案--------------------//SQL查询返回结果集对象
public ResultSet SqlSelect(String sqlstr) {
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sqlstr);
} catch (
SQLException ex) {
ex.printStackTrace();
rs = null;
}
return rs;
}
//验证用户是否存在
public boolean is(String sqlstr) {
rs = SqlSelect(sqlstr);
try {
if (rs.next()) {
return true;
}
return false;
} catch (SQLException ex) {
ex.printStackTrace();
return false;
}
}