/**
- 查找用户信息
- **/ public Users findUsersUid(int uId) { Connection con = DBTools.getConnection(); String sql = "select * from users where uId=?";
PreparedStatement preparedStatement=null;
ResultSet resultSet=null;
try {
preparedStatement= con.prepareStatement(sql);
preparedStatement.setInt(1, uId); resultSet= preparedStatement.executeQuery(); Users u = null;
if (resultSet.next()) {
uId = resultSet.getInt(1);
String uQQ = resultSet.getString(2);
String uPwd = resultSet.getString(3);
String uName = resultSet.getString(4);
int uAge = resultSet.getInt(5);
String uGender = resultSet.getString(6);
String uImage = resultSet.getString(7);
String uEmail = resultSet.getString(8);
int uStatus = resultSet.getInt(9);
Date uLastLoginTime = resultSet.getDate(10);
Date uRegisterTime = resultSet.getDate(11);
String uRemark = resultSet.getString(12); u = new Users(uId, uQQ, uPwd, uName, uAge, uGender,
uImage, uEmail, uStatus, uLastLoginTime, uRegisterTime,
uRemark);
}
return u; } catch (SQLException e) { e.printStackTrace();
return null; // 返回-1表示发生异常
} finally {
DBTools.closeAll(con, preparedStatement, resultSet);
} }
这是查询的DAO方法,但是怎么调用呢,是不是还要查找账号
方法调用,无外乎2种,一种静态方法,直接类调用,还一种new个对象,通过对象调用