Пример #1
0
 /** 插入数据 */
 public Integer insertUser(User user) {
   QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());
   try {
     String sql = "INSERT INTO user VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     Object param[] = {
       getID(),
       user.getUsername(),
       user.getPassword(),
       user.getSex(),
       user.getProfession(),
       user.getFavourite(),
       user.getNote(),
       user.getType()
     };
     int update = queryRunner.update(sql, param);
     return update;
   } catch (SQLException e) {
     e.printStackTrace();
     return null;
   }
 }
Пример #2
0
  /**
   * 数据库操作 更新个人用户数据 管理用户
   *
   * @param user
   */
  public void updateUserInfoServlet(User user) {
    QueryRunner queryRunner = new QueryRunner(JdbcUtils.getDataSource());

    String sql =
        "UPDATE user SET username = ?, password = ?, sex = ?, profession = ?, favourite = ?, note = ?, type = ?  WHERE id = ?;";

    try {
      queryRunner.update(
          sql,
          new Object[] {
            user.getUsername(),
            user.getPassword(),
            user.getSex(),
            user.getProfession(),
            user.getFavourite(),
            user.getNote(),
            user.getType(),
            user.getId()
          });
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }