import java.sql.*; import sqlj.runtime.ref.DefaultContext; import oracle.sqlj.runtime.Oracle; public class JDBCInteropDemo { // in this example, we use an iterator that is inner class #sql public static iterator Employees ( String ename, double sal ) ; public static void main(String[] args) throws SQLException { if (args.length != 1) { System.out.println("usage: JDBCInteropDemo "); System.exit(1); } /* if you're using a non-Oracle JDBC Driver, add a call here to DriverManager.registerDriver() to register your Driver */ // set the default connection to the URL, user, and password // specified in your connect.properties file Oracle.connect(JDBCInteropDemo.class, "connect.properties"); Connection conn = DefaultContext.getDefaultContext().getConnection(); // create a JDBCStatement object to execute a dynamic query Statement stmt = conn.createStatement(); String query = "SELECT ename, sal FROM emp WHERE "; query += args[0]; // use the result set returned by executing the query to create // a new strongly-typed SQLJ iterator ResultSet rs = stmt.executeQuery(query); Employees emps; #sql emps = { CAST :rs }; while (emps.next()) { System.out.println(emps.ename() + " earns " + emps.sal()); } emps.close(); stmt.close(); } }