一段代码求助,为什么bool的返回值总是false
public boolean checklogin(String Username,String Password) {String url = "jdbc:mysql://localhost/jspwork";
String userName = "root";
String password = "root";
String sql = null;
Connection conn = null;
Statement stmt = null;
String s;
boolean bool=false;
try {
//第一步:加载驱动器
Class.forName("com.mysql.jdbc.Driver");
} catch(ClassNotFoundException e) {
System.err.print("ClassNotFoundException");
}
try {
//第二步:调用DriverManager.getConnection静态方法得到数据库连接
conn = DriverManager.getConnection(url, userName, password);
//创建Statement语句
stmt = conn.createStatement();
sql =" select * from userfo where username="+"\'"+Username+"\'";
//使用Statement语句对象执行SQL语句
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
s=rs.getString(2);
if(s==Password){
bool=true;
}
}
} catch(SQLException e) {
// System.err.println("Query SQLException");
} finally {
//关闭语句和数据库连接
try {
stmt.close();
conn.close();
} catch(SQLException e) {
System.err.println("Close SQLException");
}
}
return bool;
}