<%@ page import="sqlj.runtime.ref.DefaultContext,oracle.sqlj.runtime.Oracle" %>

<HTML>
<HEAD> <TITLE> The SQLJSelectInto JSP  </TITLE> </HEAD>
<BODY BGCOLOR=white>

<%
   String connStr=request.getParameter("connStr");
   if (connStr==null) {
     connStr=(String)session.getValue("connStr");
   } else {
     session.putValue("connStr",connStr);
   }
   if (connStr==null) { %>
<jsp:forward page="../setconn.jsp" />
<%
   }
%>

<%
   String empno = request.getParameter("empno"); 
   if (empno != null) { %>
      <H3> Employee # <%=empno %> Details: </H3>
      <%= runQuery(connStr,empno) %>
      <HR><BR>
<% }  %>

<B>Enter an employee number:</B>
<FORM METHOD=get> 
<INPUT TYPE="text" NAME="empno" SIZE=10>
<INPUT TYPE="submit" VALUE="Ask Oracle");
</FORM>
</BODY>
</HTML>
<%! 
  private String runQuery(String connStr, String empno) throws java.sql.SQLException {
     DefaultContext dctx = null;
     String ename = null;  double sal = 0.0;  String hireDate = null; 
     StringBuffer sb = new StringBuffer();
     try {
	dctx = Oracle.getConnection(connStr, "scott", "tiger");
	#sql [dctx] { SELECT ename, sal, TO_CHAR(hiredate, 'DD-MON-YYYY') 
                      INTO :ename, :sal, :hireDate
                      FROM scott.emp WHERE UPPER(empno) = UPPER(:empno)
        };
	sb.append("<BLOCKQUOTE><BIG><B><PRE>\n");
        sb.append("Name       : " + ename + "\n");
	sb.append("Salary     : " + sal + "\n");
	sb.append("Date hired : " + hireDate);
        sb.append("</PRE></B></BIG></BLOCKQUOTE>");

     } catch (java.sql.SQLException e) {
         sb.append("<P> SQL error: <PRE> " + e + " </PRE> </P>\n");
     } finally {
         if (dctx!= null) dctx.close();
     }
     return sb.toString();
  }
%>
