/* Import SQLExceptions class. The SQLException comes from
JDBC. Executable #sql clauses result in calls to JDBC, so methods
containing executable #sql clauses must either catch or throw
SQLException.
*/
import java.sql.SQLException ;
import oracle.sqlj.runtime.Oracle;
 

// iterator for the select

#sql iterator MyIter (String sname, String title);

class TestUnivDB
{
    //Main method
    public static void main (String args[])
    {
        try {
                // set the default connection to the URL, user, and password
                // specified in your connect.properties file
                Oracle.connect(TestUnivDB.class, "connect.properties");

                TestUnivDB ti = new TestUnivDB();
                ti.runExample();
        } catch (SQLException e) {
            System.err.println("Error running the example: " + e);
        }
    } //End of method main

    //Method that runs the example
    void runExample() throws SQLException
    {
        MyIter iter;
        #sql iter = { select s.sname, c.title from students s, courses c,
                          enrollments e where s.sid = e.sid and c.cid = e.cid };
        while (iter.next()) {
            System.out.println(iter.sname() + ", " + iter.title());
        }
    }
}