/*@lineinfo:filename=sqljPosIteratorExample*//*@lineinfo:user-code*//*@lineinfo:1^1*/import java.sql.*;
import oracle.sqlj.runtime.Oracle;
class sqljPosIteratorExample {
 public static void main (String args []){
  try {
   // Datenbank-Verbindung aufbauen
   Oracle.connect(sqljPosIteratorExample.class, "conn.props");
   // Deklaration des Iterators nur mit Typen
   /*@lineinfo:generated-code*//*@lineinfo:9^4*/

//  ************************************************************
//  SQLJ iterator declaration:
//  ************************************************************

class CountryPosIterator
extends sqlj.runtime.ref.ResultSetIterImpl
implements sqlj.runtime.PositionedIterator
{
  public CountryPosIterator(sqlj.runtime.profile.RTResultSet resultSet)
    throws java.sql.SQLException
  {
    super(resultSet, 2);
    m_rs = (oracle.jdbc.OracleResultSet) resultSet.getJDBCResultSet();
  }
  private oracle.jdbc.OracleResultSet m_rs;
  public String getCol1()
    throws java.sql.SQLException
  {
    return (String)m_rs.getString(1);
  }
  public int getCol2()
    throws java.sql.SQLException
  {
    int __sJtmp = m_rs.getInt(2);
    if (m_rs.wasNull()) throw new sqlj.runtime.SQLNullException(); else return __sJtmp;
  }
}


//  ************************************************************

/*@lineinfo:user-code*//*@lineinfo:9^48*/
   // Hilfsvariablen der Hostsprache
   String name = "";
   int pop = 0;
   CountryPosIterator cIter;   // Iteratorinstanz definieren
   // Initialisieren des Iterators mit der SQL-Anweisung
   /*@lineinfo:generated-code*//*@lineinfo:15^4*/

//  ************************************************************
//  #sql cIter = { SELECT name, population FROM country };
//  ************************************************************

{
  // declare temps
  oracle.jdbc.OraclePreparedStatement __sJT_st = null;
  sqlj.runtime.ref.DefaultContext __sJT_cc = sqlj.runtime.ref.DefaultContext.getDefaultContext(); if (__sJT_cc==null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_CONN_CTX();
  sqlj.runtime.ExecutionContext.OracleContext __sJT_ec = ((__sJT_cc.getExecutionContext()==null) ? sqlj.runtime.ExecutionContext.raiseNullExecCtx() : __sJT_cc.getExecutionContext().getOracleContext());
  try {
   String theSqlTS = "SELECT name, population FROM country";
   __sJT_st = __sJT_ec.prepareOracleStatement(__sJT_cc,"0sqljPosIteratorExample",theSqlTS);
   // execute query
   cIter = new CountryPosIterator(new sqlj.runtime.ref.OraRTResultSet(__sJT_ec.oracleExecuteQuery(),__sJT_st,"0sqljPosIteratorExample",null));
  } finally { __sJT_ec.oracleCloseQuery(); }
}


//  ************************************************************

/*@lineinfo:user-code*//*@lineinfo:15^54*/
   // Abarbeitung der Ergebnismenge durch Iteration
   while (true) { // hole naechsten Datensatz
      /*@lineinfo:generated-code*//*@lineinfo:18^7*/

//  ************************************************************
//  #sql { FETCH :cIter  };
//  ************************************************************

{
  CountryPosIterator __sJT_iter = cIter;
  if (__sJT_iter.next())
  {
    name = __sJT_iter.getCol1();
    pop = __sJT_iter.getCol2();
  }
}


//  ************************************************************

/*@lineinfo:user-code*//*@lineinfo:18^40*/
      //Ende des Iterators erreicht?
      if(cIter.endFetch()) break;
      System.out.println(name + " has " +
                         pop + " inhabitants.");   }
   cIter.close();
   } catch (SQLException e) { System.err.println(e.getMessage()); }
 }}/*@lineinfo:generated-code*/