Esempio n. 1
0
  public Course insert(int cid, String title, Dept dept) {
    try {
      // make sure that the cid is currently unused
      if (find(cid) != null) return null;

      String cmd = "insert into COURSE(CId, Title, DeptId) " + "values(?, ?, ?, ?)";
      PreparedStatement pstmt = conn.prepareStatement(cmd);
      pstmt.setInt(1, cid);
      pstmt.setString(2, title);
      pstmt.setInt(3, dept.getId());
      pstmt.executeUpdate();
      return new Course(this, cid, title, dept);
    } catch (SQLException e) {
      dbm.cleanup();
      throw new RuntimeException("error inserting new course", e);
    }
  }
Esempio n. 2
0
 public boolean equals(Object obj) {
   if (obj instanceof Dept == false) return false;
   if (this == obj) return true;
   Dept other = (Dept) obj;
   return new EqualsBuilder().append(getDeptId(), other.getDeptId()).isEquals();
 }