示例#1
0
  /**
   * Maakt de opgegeven security aan in de database
   *
   * @param entity Het object dat moet worden aangemaakt in de database
   * @return
   * @throws StockPlayException
   */
  public boolean update(Exchange entity) throws StockPlayException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      try {
        conn = OracleConnection.getConnection();
        stmt = conn.prepareStatement(UPDATE_EXCHANGE);

        stmt.setString(3, entity.getSymbol());
        stmt.setString(1, entity.getName());
        stmt.setString(2, entity.getLocation());

        return stmt.executeUpdate() == 1;

      } finally {
        if (rs != null) {
          rs.close();
        }
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      }
    } catch (SQLException ex) {
      throw new SubsystemException(SubsystemException.Type.DATABASE_FAILURE, ex.getCause());
    }
  }
示例#2
0
  public Exchange findById(String symbol) throws StockPlayException {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
      try {
        conn = OracleConnection.getConnection();
        stmt = conn.prepareStatement(SELECT_EXCHANGE);

        stmt.setString(1, symbol);

        rs = stmt.executeQuery();
        if (rs.next()) {
          Exchange tExchange = new Exchange(symbol);
          tExchange.setName(rs.getString(1));
          tExchange.setLocation(rs.getString(2));
          return tExchange;
        } else {
          throw new InvocationException(
              InvocationException.Type.NON_EXISTING_ENTITY,
              "There is no security with symbol '" + symbol + "'");
        }
      } finally {
        if (rs != null) {
          rs.close();
        }
        if (stmt != null) {
          stmt.close();
        }
        if (conn != null) {
          conn.close();
        }
      }
    } catch (SQLException ex) {
      throw new SubsystemException(SubsystemException.Type.DATABASE_FAILURE, ex.getCause());
    }
  }