Example #1
0
  /** update a project */
  public void update(Project project) {

    PreparedStatement stmt = null;
    try {
      String sql =
          "update Projects "
              + "set Title = ?, RecordSperImage = ?, FirstYCoord = ?, RecordHeight = ? "
              + "where ProjectID = ?";
      stmt = db.getConnection().prepareStatement(sql);
      stmt.setString(1, project.getTitle());
      stmt.setInt(2, project.getRecordsPerImage());
      stmt.setInt(3, project.getFirstYCoord());
      stmt.setInt(4, project.getRecordHeight());
      stmt.setInt(5, project.getProjectID());

      if (stmt.executeUpdate() == 1) {
        System.out.println("Update success");
      } else {
        System.out.println("Update fail");
      }
    } catch (SQLException e) {
      System.out.println("Can't execute update");
      e.printStackTrace();
    } finally {
      try {
        if (stmt != null) stmt.close();
      } catch (SQLException e) {
        System.out.println("Can't execute connect");
        e.printStackTrace();
      }
    }
  }