<%@ page import="java.sql.*" %> <%@ page import="sqlj.runtime.ref.DefaultContext,oracle.sqlj.runtime.Oracle" %> <%! #sql iterator Empiter(String ename, double sal, java.sql.Date hiredate) %> <% String connStr=request.getParameter("connStr"); if (connStr==null) { connStr=(String)session.getValue("connStr"); } else { session.putValue("connStr",connStr); } if (connStr==null) { %> <% } %> <% DefaultContext dctx = null; dctx = Oracle.getConnection(connStr, "scott", "tiger"); %> The SqljIterator SQLJSP <% String user; #sql [dctx] {SELECT user INTO :user FROM dual}; %>

Hello, <%= user %>!


I will use a SQLJ iterator to get employee data from EMP table in schema SCOTT..

<% Empiter emps; try { #sql [dctx] emps = { SELECT ename, sal, hiredate FROM scott.emp ORDER BY ename}; if (emps.next()) { %> <% while (emps.next()) { %> <% } %>
Employee Name Salary
<%= emps.ename() %> <%= emps.sal() %>
<%= emps.ename() %> <%= emps.sal() %>
<% } else { %>

Sorry, the query returned no rows!

<% } emps.close(); } catch (SQLException e) { %>

There was an error doing the query:

 <%= e %> 

<% } %>