コード例 #1
0
  /** Inserts a new row in the carrito_compras table. */
  public CarritoComprasPk insert(CarritoCompras dto) throws CarritoComprasDaoException {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
      // get the user-specified connection or get a connection from the ResourceManager
      conn = isConnSupplied ? userConn : ResourceManager.getConnection();

      stmt = conn.prepareStatement(SQL_INSERT);
      int index = 1;
      stmt.setString(index++, dto.getIdCarrito());
      stmt.setDouble(index++, dto.getTotal());
      stmt.setDouble(index++, dto.getSubtotal());
      stmt.setDouble(index++, dto.getImpuestos());
      System.out.println("Executing " + SQL_INSERT + " with DTO: " + dto);
      int rows = stmt.executeUpdate();
      long t2 = System.currentTimeMillis();
      System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)");
      reset(dto);
      return dto.createPk();
    } catch (Exception _e) {
      _e.printStackTrace();
      throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e);
    } finally {
      ResourceManager.close(stmt);
      if (!isConnSupplied) {
        ResourceManager.close(conn);
      }
    }
  }
コード例 #2
0
  /** Deletes a single row in the carrito_compras table. */
  public void delete(CarritoComprasPk pk) throws CarritoComprasDaoException {
    long t1 = System.currentTimeMillis();
    // declare variables
    final boolean isConnSupplied = (userConn != null);
    Connection conn = null;
    PreparedStatement stmt = null;

    try {
      // get the user-specified connection or get a connection from the ResourceManager
      conn = isConnSupplied ? userConn : ResourceManager.getConnection();

      System.out.println("Executing " + SQL_DELETE + " with PK: " + pk);
      stmt = conn.prepareStatement(SQL_DELETE);
      stmt.setString(1, pk.getIdCarrito());
      int rows = stmt.executeUpdate();
      long t2 = System.currentTimeMillis();
      System.out.println(rows + " rows affected (" + (t2 - t1) + " ms)");
    } catch (Exception _e) {
      _e.printStackTrace();
      throw new CarritoComprasDaoException("Exception: " + _e.getMessage(), _e);
    } finally {
      ResourceManager.close(stmt);
      if (!isConnSupplied) {
        ResourceManager.close(conn);
      }
    }
  }