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

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

class CountryIter
extends sqlj.runtime.ref.ResultSetIterImpl
implements sqlj.runtime.NamedIterator
{
  public CountryIter(sqlj.runtime.profile.RTResultSet resultSet)
    throws java.sql.SQLException
  {
    super(resultSet);
    nameNdx = findColumn("name");
    populationNdx = findColumn("population");
    m_rs = (oracle.jdbc.OracleResultSet) resultSet.getJDBCResultSet();
  }
  private oracle.jdbc.OracleResultSet m_rs;
  public String name()
    throws java.sql.SQLException
  {
    return (String)m_rs.getString(nameNdx);
  }
  private int nameNdx;
  public int population()
    throws java.sql.SQLException
  {
    int __sJtmp = m_rs.getInt(populationNdx);
    if (m_rs.wasNull()) throw new sqlj.runtime.SQLNullException(); else return __sJtmp;
  }
  private int populationNdx;
}


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

/*@lineinfo:user-code*//*@lineinfo:8^57*/
   // Iteratorinstanz definieren
   CountryIter cIter;
   // Initialisieren des Iterators mit der SQL-Anweisung
   /*@lineinfo:generated-code*//*@lineinfo:12^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,"0sqljNamedIteratorExample",theSqlTS);
   // execute query
   cIter = new CountryIter(new sqlj.runtime.ref.OraRTResultSet(__sJT_ec.oracleExecuteQuery(),__sJT_st,"0sqljNamedIteratorExample",null));
  } finally { __sJT_ec.oracleCloseQuery(); }
}


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

/*@lineinfo:user-code*//*@lineinfo:12^54*/
   // Abarbeitung der Ergebnismenge durch Iteration
   while (cIter.next()) {
      System.out.println(cIter.name() + " has " +
                cIter.population() + " inhabitants."); }
   cIter.close();
  }
  catch (SQLException e) { System.err.println(e.getMessage()); } }}/*@lineinfo:generated-code*/