Ejemplo n.º 1
0
 public User findUserById(int id) {
   String sql = "select * from user where userid=" + id;
   DBConnection db = new DBConnection();
   conn = db.getConn();
   User user = new User();
   try {
     ps = conn.prepareStatement(sql);
     rs = ps.executeQuery();
     while (rs.next()) {
       user.setUserid(rs.getInt("userid"));
       user.setUsername(rs.getString("username"));
       user.setPassword(rs.getString("password"));
       user.setRealname(rs.getString("realname"));
       user.setEmail(rs.getString("email"));
       user.setStatus(rs.getInt("status"));
       user.setRoleid(rs.getInt("roleid"));
     }
     rs.close();
     ps.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return user;
 }
Ejemplo n.º 2
0
 public Page findPageByUserName(String username, int pageNo, int pageSize, int totalCount) {
   Page page = new Page();
   String sql;
   if (username != null && username != "") {
     sql =
         "select * from user where username like '%"
             + username
             + "%' limit "
             + page.getOffset(pageNo)
             + ","
             + pageSize;
   } else {
     sql = "select * from user limit " + page.getOffset(pageNo) + "," + pageSize;
   }
   DBConnection db = new DBConnection();
   conn = db.getConn();
   List<User> userList = new ArrayList<User>();
   try {
     ps = conn.prepareStatement(sql);
     rs = ps.executeQuery();
     while (rs.next()) {
       User user = new User();
       user.setUserid(rs.getInt("userid"));
       user.setUsername(rs.getString("username"));
       user.setPassword(rs.getString("password"));
       user.setRealname(rs.getString("realname"));
       user.setEmail(rs.getString("email"));
       user.setStatus(rs.getInt("status"));
       user.setRoleid(rs.getInt("roleid"));
       userList.add(user);
     }
     rs.close();
     ps.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   page.setPageItem(userList);
   return page;
 }