数据库操作得不到正确返回
public String login(String tableName, String dbuser, String dbpassword) {
Vector user = new Vector();
Vector password = new Vector();
String url = urlRoot + dbName;
String SQLCommand = "SELECT * FROM " + tableName + ";";
//String SQLCommand2 = "SELECT password FROM" + tableName + ";";
String message = null;
try {
Connection con = DriverManager.getConnection(url);
Statement stms = con.createStatement();
ResultSet rs = stms.executeQuery(SQLCommand);
while(rs.next()) {
//System.out.print(rs.getString("name"));
user.add(rs.getString("name"));
password.add(rs.getString("password"));
}
} catch(SQLException sqlExc) {
reportException(sqlExc.getMessage());
}
if(user.contains((String)dbuser))
if(password.contains((String)dbpassword))
message = "你以管理员"+dbuser+"的身份登陆";
else
message = "你输入的密码有误";
else
message = "你输入的用户名不存在";
return message;
}
为什么我总是返回 你输入的用户名不存在?
Vector user = new Vector();
Vector password = new Vector();
String url = urlRoot + dbName;
String SQLCommand = "SELECT * FROM " + tableName + ";";
//String SQLCommand2 = "SELECT password FROM" + tableName + ";";
String message = null;
try {
Connection con = DriverManager.getConnection(url);
Statement stms = con.createStatement();
ResultSet rs = stms.executeQuery(SQLCommand);
while(rs.next()) {
//System.out.print(rs.getString("name"));
user.add(rs.getString("name"));
password.add(rs.getString("password"));
}
} catch(SQLException sqlExc) {
reportException(sqlExc.getMessage());
}
if(user.contains((String)dbuser))
if(password.contains((String)dbpassword))
message = "你以管理员"+dbuser+"的身份登陆";
else
message = "你输入的密码有误";
else
message = "你输入的用户名不存在";
return message;
}