FileDocCategorySizeDatePackage
TestCursorPositioning.javaAPI DocExample5356Sun Jun 24 21:57:38 BST 2001None

TestCursorPositioning

public class TestCursorPositioning extends Object

Fields Summary
Connection
conn
Constructors Summary
public TestCursorPositioning()

    try {
      DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
      conn = DriverManager.getConnection(
       "jdbc:oracle:thin:@dssw2k01:1521:orcl", "scott", "tiger");
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
    }
  
Methods Summary
protected voidfinalize()

    if (conn != null) 
      try { conn.close(); } catch (SQLException ignore) { }
    super.finalize();
  
private java.lang.StringformatConcurrency(int Concurrency)

    switch (Concurrency) {
      case ResultSet.CONCUR_READ_ONLY:
        return "CONCUR_READ_ONLY";
      case ResultSet.CONCUR_UPDATABLE:
        return "CONCUR_UPDATABLE";
      default:
        return "CONCUR_UNKNOWN";
    }
  
private java.lang.StringformatType(int type)

    switch (type) {
      case ResultSet.TYPE_FORWARD_ONLY: 
        return "TYPE_FORWARD_ONLY";
      case ResultSet.TYPE_SCROLL_INSENSITIVE: 
        return "TYPE_SCROLL_INSENSITIVE";
      case ResultSet.TYPE_SCROLL_SENSITIVE: 
        return "TYPE_SCROLL_SENSITIVE";
      default:
        return "TYPE_UNKNOWN";
    }
  
public static voidmain(java.lang.String[] args)

    new TestCursorPositioning().process();
  
public voidprocess()

    int       rows = 0;
    ResultSet rslt = null;
    Statement stmt = null;

    try {
      stmt = conn.createStatement();
      rslt = stmt.executeQuery(
       "select code, " + 
       "       description, " + 
       "       inactive_date " +
       "from   PERSON_IDENTIFIER_TYPE");
 
      System.out.println("type          = " +
       formatType(stmt.getResultSetType()));

      System.out.println("concurrency   = " +
       formatConcurrency(stmt.getResultSetConcurrency()));

      System.out.println("before first  = " + 
       new Boolean(rslt.isBeforeFirst()).toString());

      while (rslt.next()) {
        rows++;
        if (rslt.isFirst()) 
          System.out.println("the first row = " + Integer.toString(rows));
        //  Contrary to JDBC API doc, but in accordance with Oracle's doc
        //if (rslt.isLast())
        //  System.out.println("the last row  = " + Integer.toString(rows));
      }
      System.out.println("after last    = " + 
       new Boolean(rslt.isAfterLast()).toString());

      System.out.println(Integer.toString(rows) + " rows selected");

      System.out.println(" ");
      rslt.close();
      rslt = null;
      stmt.close();
      stmt = null;
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (rslt != null) 
        try { rslt.close(); } catch (SQLException ignore) { }
      if (stmt != null) 
        try { stmt.close(); } catch (SQLException ignore) { }
    }

    rows = 0;
    try {
      stmt = conn.createStatement(
       ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      rslt = stmt.executeQuery(
       "select code, " +
       "       description, " +
       "       inactive_date " + 
       "from   PERSON_IDENTIFIER_TYPE");

      System.out.println("type          = " +
       formatType(stmt.getResultSetType()));

      System.out.println("concurrency   = " +
       formatConcurrency(stmt.getResultSetConcurrency()));

      System.out.println("before first  = " +
       new Boolean(rslt.isBeforeFirst()).toString());

      while (rslt.next()) {
        rows++;
        if (rslt.isFirst()) 
          System.out.println("the first row = " + Integer.toString(rows));
        if (rslt.isLast())
          System.out.println("the last row  = " + Integer.toString(rows));
      }
      System.out.println("after last    = " + 
       new Boolean(rslt.isAfterLast()).toString());

      System.out.println(Integer.toString(rows) + " rows selected");

      if (rslt.previous())
        System.out.println("the prev row  = " +
         Integer.toString(rslt.getRow()));

      if (rslt.relative(-1))
        System.out.println("rel -1 row    = " +
         Integer.toString(rslt.getRow()));

      if (rslt.absolute(2))
        System.out.println("abs 2 row     = " +
         Integer.toString(rslt.getRow()));

      rslt.beforeFirst();

      System.out.println("bef first row = " +
       Integer.toString(rslt.getRow()));

      if (rslt.first())
        System.out.println("first row     = " +
         Integer.toString(rslt.getRow()));

      if (rslt.last())
       System.out.println("last row      = " +
        Integer.toString(rslt.getRow()));

      rslt.afterLast();

      System.out.println("aft last row  = " +
       Integer.toString(rslt.getRow()));

      System.out.println(" ");
      rslt.close();
      rslt = null;
      stmt.close();
      stmt = null;
    }
    catch (SQLException e) {
      System.err.println(e.getMessage());
    }
    finally {
      if (rslt != null) 
        try { rslt.close(); } catch (SQLException ignore) { }
      if (stmt != null) 
        try { stmt.close(); } catch (SQLException ignore) { }
    }