当在数据库中查询出一条记录的时候,while(resultSet.next())为什么为false?如果是多条记录则是true。 10
publicbooleanisLogin(Stringusername,Stringpassword)throwsException{getConnectionPoolg...
public boolean isLogin(String username,String password) throws Exception{
getConnectionPool gcp = new getConnectionPool();
PreparedStatement statement = null;
Connection conn = null;
try {
conn = gcp.getConnection();
String sql = "select userid,password from managersoft_user t where userid=?";
statement = conn.prepareStatement(sql);
statement.setString(1, username);
//statement.setString(2, password);
ResultSet rs = statement.executeQuery();
while(rs.next()){
System.out.println(rs.getString("userid"));
return true;
}
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
} 展开
getConnectionPool gcp = new getConnectionPool();
PreparedStatement statement = null;
Connection conn = null;
try {
conn = gcp.getConnection();
String sql = "select userid,password from managersoft_user t where userid=?";
statement = conn.prepareStatement(sql);
statement.setString(1, username);
//statement.setString(2, password);
ResultSet rs = statement.executeQuery();
while(rs.next()){
System.out.println(rs.getString("userid"));
return true;
}
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询