Example #1
0
  @Override
  public boolean update(Object T) {
    Aanbieding aanbieding = (Aanbieding) T;

    try {
      Connection connection = null;
      connection = GetConnection.getDBConnection();
      if (connection != null) {
        System.out.println("|| Connection ready || ");
      } else {
        System.out.println("|| Connection failed ||");
      }
      PreparedStatement ps =
          connection.prepareStatement(
              "update aanbiedingen set eindtijd = ?, startprijs =?, image =? where id = ?");
      ps.setTimestamp(1, aanbieding.getEindtijd());
      ps.setDouble(2, aanbieding.getStartprijs());
      ps.setBytes(3, aanbieding.getImg());
      ps.setInt(4, aanbieding.getId());
      ResultSet rs = ps.executeQuery();
      rs.close();
      ps.close();
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    GetConnection.closeConnection();
    return true;
  }
Example #2
0
  @Override
  public void delete(Object T) {
    Aanbieding aanbieding = (Aanbieding) T;
    try {
      Connection connection = null;
      connection = GetConnection.getDBConnection();
      if (connection != null) {
        System.out.println("|| Connection ready || ");
      } else {
        System.out.println("|| Connection failed ||");
      }
      if (aanbieding.getGebruikers_klantnr() == 0) {

        PreparedStatement ps =
            connection.prepareStatement("delete from biedingen where aanbiedingen_id = ?");
        ps.setInt(1, aanbieding.getId());
        ResultSet rs = ps.executeQuery();
        rs.close();
        ps.close();

        PreparedStatement ps2 =
            connection.prepareStatement("delete from aanbiedingen where id = ?");
        ps2.setInt(1, aanbieding.getId());
        ResultSet rs2 = ps2.executeQuery();
        rs2.close();
        ps2.close();

      } else {
        PreparedStatement ps3 =
            connection.prepareStatement(
                "delete from aanbiedingen where id = ? and gebruikers_klantnr =?");
        ps3.setInt(1, aanbieding.getId());
        ps3.setInt(2, aanbieding.getGebruikers_klantnr());
        ResultSet rs3 = ps3.executeQuery();
        rs3.close();
        ps3.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    GetConnection.closeConnection();
  }
Example #3
0
  @Override
  public boolean create(Object T) {
    Aanbieding aanbieding = (Aanbieding) T;
    Connection connection = null;
    connection = GetConnection.getDBConnection();
    try {
      if (connection != null) {

        System.out.println("|| Connection ready || ");
      } else {
        System.out.println("|| Connection failed ||");
      }
      PreparedStatement ps =
          connection.prepareStatement(
              "INSERT INTO AANBIEDINGEN (STARTPRIJS, EINDTIJD, GEBRUIKERS_KLANTNR, DRUKKEN_BOEKEN_ISBN, DRUKKEN_NUMMER, INSERT_DATE, IMAGE) VALUES(?,?,?,?,?,sysdate, ?)");
      ps.setDouble(1, aanbieding.getStartprijs());
      ps.setTimestamp(2, aanbieding.getEindtijd());
      ps.setInt(3, aanbieding.getGebruikers_klantnr());
      ps.setString(4, aanbieding.getDrukken_isbn());
      ps.setInt(5, aanbieding.getDrukken_nummer());
      ps.setBytes(6, aanbieding.getImg());
      ResultSet rs = ps.executeQuery();
      rs.close();
      ps.close();
      if (!VeilingService.checkDruk(aanbieding.getDrukken_isbn(), aanbieding.getDrukken_nummer())) {
        PreparedStatement ps2 =
            connection.prepareStatement("INSERT INTO DRUKKEN (BOEKEN_ISBN, NUMMER) VALUES (?, ?)");
        ps2.setString(1, aanbieding.getDrukken_isbn());
        ps2.setInt(2, aanbieding.getDrukken_nummer());
        ResultSet rs2 = ps2.executeQuery();
        rs2.close();
        ps2.close();
      }

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    GetConnection.closeConnection();
    return true;
  }