コード例 #1
0
  public static int updateStudy(String code, Study study) {
    ConnectionPool pool = ConnectionPool.getInstance();
    Connection connection = pool.getConnection();
    PreparedStatement ps = null;

    String query =
        "UPDATE study SET "
            + "name = ?, description = ?, question = ? , imageURL = ?, requestedParticipants = ?,"
            + "numOfParticipants = ?, status = ?"
            + "WHERE code = ?";

    try {
      ps = connection.prepareStatement(query);

      ps.setString(1, study.getName());
      ps.setString(2, study.getDescription());
      ps.setString(3, study.getQuestion());
      ps.setString(4, study.getImageURL());
      ps.setInt(5, study.getRequestedParticipants());
      ps.setInt(6, study.getNumOfParticipants());
      ps.setString(7, study.getStatus());
      ps.setString(8, code);

      return ps.executeUpdate();
    } catch (SQLException e) {
      System.out.println(e);
      return 0;
    } finally {
      DBUtil.closePreparedStatement(ps);
      pool.freeConnection(connection);
    }
  }
コード例 #2
0
  public static int addStudy(Study study) {

    ConnectionPool pool = ConnectionPool.getInstance();
    Connection connection = pool.getConnection();
    PreparedStatement ps = null;

    String query =
        "INSERT INTO study (name,description,creatorEmail, dateCreated, "
            + "question, imageURL, requestedParticipants, numOfParticipants, status) "
            + "VALUES (?,?,?,?,?,?,?,?,?)";
    try {
      ps = connection.prepareStatement(query);
      ps.setString(1, study.getName());

      ps.setString(2, study.getDescription());
      ps.setString(3, study.getCreatorEmail());
      ps.setTimestamp(4, study.getDateCreated());
      ps.setString(5, study.getQuestion());
      ps.setString(6, study.getImageURL());
      ps.setInt(7, study.getRequestedParticipants());
      ps.setInt(8, study.getNumOfParticipants());
      ps.setString(9, study.getStatus());

      return ps.executeUpdate();
    } catch (SQLException e) {
      System.out.println(e);
      return 0;
    } finally {
      DBUtil.closePreparedStatement(ps);
      pool.freeConnection(connection);
    }
  }