Esempio n. 1
0
 public int addUser(User user) {
   int flag = 0;
   String sql = "insert into user values(userid,?,?,?,?,?,?)";
   DBConnection db = new DBConnection();
   conn = db.getConn();
   try {
     ps = conn.prepareStatement(sql);
     ps.setString(1, user.getUsername());
     ps.setString(2, user.getPassword());
     ps.setString(3, user.getRealname());
     ps.setString(4, user.getEmail());
     ps.setInt(5, user.getStatus());
     ps.setInt(6, user.getRoleid());
     flag = ps.executeUpdate();
     ps.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return flag;
 }
Esempio n. 2
0
 public int updateUser(User user) {
   int flag = 0;
   String sql =
       "update user set username=?,password=?,realname=?,email=?,status=?,roleid=? where userid=?";
   DBConnection db = new DBConnection();
   conn = db.getConn();
   try {
     ps = conn.prepareStatement(sql);
     ps.setString(1, user.getUsername());
     ps.setString(2, user.getPassword());
     ps.setString(3, user.getRealname());
     ps.setString(4, user.getEmail());
     ps.setInt(5, user.getStatus());
     ps.setInt(6, user.getRoleid());
     ps.setInt(7, user.getUserid());
     flag = ps.executeUpdate();
     ps.close();
     conn.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return flag;
 }