Ejemplo n.º 1
0
  /*
   * Result cursors are bidirectional.  You can use hasNext, next,
   * hasPrevious, previous, isFirst, first, isLast, last, isBeforeFirst,
   * beforeFirst, isAfterLast, afterLast.  You can also use Iterator and
   * ListIterator.
   */
  static void movingBackAndForth(Database db) throws DatabaseException {
    Result<Order> result = db.queryObject(Order.class);

    while (result.hasNext()) System.out.println(result.next());

    while (result.hasPrevious()) System.out.println(result.previous());

    result.last();

    System.out.println();

    System.out.println(result.current());

    while (result.hasPrevious()) System.out.println(result.previous());

    System.out.println();

    result = db.queryObject(Order.class);

    ListIterator it;

    for (it = result.listIterator(); it.hasNext(); ) System.out.println(it.next());

    for (; it.hasPrevious(); ) System.out.println(it.previous());
  }
Ejemplo n.º 2
0
  /*
   * If your result set concurrency is ResultSet.CONCUR_UPDATABLE,
   * you can update rows in the result on the fly.
   */
  static void updateRow(Database db) throws DatabaseException {
    // The following two method calls depend on the database being used, they may be optional
    db.setResultSetConcurrency(ResultSet.CONCUR_UPDATABLE);
    db.setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
    Result<Customer> result = db.queryObject(Customer.class, "where customer_id = ?", "ssmith");

    for (Customer c : result) {
      result.setColumnValue("company_name", "ACBProducts");
      result.updateRow();
    }
  }
Ejemplo n.º 3
0
  /*
   * Result is a ListIterator and Iterable.
   */
  static void iteratingResults(Database db) throws DatabaseException {
    Result<Customer> result = db.queryObject(Customer.class, "where customer_id = ?", "ssmith");

    for (Customer c : result) System.out.println(c);

    result = db.queryObject(Customer.class);

    while (result.hasNext()) System.out.println(result.next());

    result = db.queryObject(Customer.class);

    for (Iterator it = result.iterator(); it.hasNext(); ) System.out.println(it.next());
  }