Пример #1
0
 public void delete(Membership membership) throws GlobalcodeException {
   Connection conn = getConnection();
   Statement st = null;
   ResultSet rs = null;
   try {
     st = conn.createStatement();
     rs =
         st.executeQuery(
             "select codigo_membership from matriculas where codigo_membership="
                 + membership.getCodigoMembership());
     if (rs.next()) {
       throw new DeleteCascadeException(
           "Membership n�o pode ser excluido pois ainda possui matriculas no sistema.");
     }
     rs.close();
     String sql = null;
     sql =
         "delete from memberships "
             + " where codigo_membership="
             + membership.getCodigoMembership();
     Debug.log(sql, 7);
     st.executeUpdate(sql);
   } catch (SQLException e) {
     throw new GlobalcodeException("Erro de DAO - RDBMS: " + e.getMessage(), e);
   } finally {
     closeResources(conn, st, rs);
   }
 }
Пример #2
0
  public void save(Membership membership) throws GlobalcodeException {
    Connection conn = getConnection();
    Statement st = null;
    ResultSet rs = null;
    try {
      st = conn.createStatement();
      String sql = null;
      // Checando se � um novo curso...
      if (membership.getCodigoMembership() == 0) {
        // long novoCodigo = this.getAutoIncrement("memberships", "codigo_membership");
        // membership.setCodigoMembership(novoCodigo);
        sql =
            "insert into memberships "
                + "(nome, endereco, data_inclusao) "
                + " values ("
                + "'"
                + membership.getNome()
                + "', "
                + "'"
                + membership.getEndereco()
                + "', "
                + "NOW()) ";

        Debug.log(sql, 7);
      } else {
        sql =
            "update memberships set "
                + "nome='"
                + membership.getNome()
                + "', "
                + "endereco='"
                + membership.getEndereco()
                + "' "
                + " where codigo_membership="
                + membership.getCodigoMembership();
        Debug.log(sql, 7);
      }
      st.executeUpdate(sql);
    } catch (SQLException e) {
      throw new GlobalcodeException("Erro de DAO - RDBMS: " + e.getMessage(), e);
    } finally {
      closeResources(conn, st, rs);
    }
  }