
<%@ page import="java.sql.*" %>

<!------------------------------------------------------------------
 * This is a basic JavaServer Page that uses a DB Access Bean and queries
 * dept and emp tables in schema scott and outputs the result in an html table.
 *  
--------------------------------------------------------------------!>

<%
   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" />
<%
   }
%>

<jsp:useBean id="dbbean" class="oracle.jsp.dbutil.DBBean" scope="session">
<jsp:setProperty name="dbbean" property="User" value="scott"/>
<jsp:setProperty name="dbbean" property="Password" value="tiger"/>
<jsp:setProperty name="dbbean" property="URL" value="<%= connStr %>" />
</jsp:useBean>

<HTML> 
  <HEAD> 
    <TITLE>
	DBBeanDemo JSP
    </TITLE>
  </HEAD>
 <BODY BGCOLOR=EOFFFO> 
 <H1> Hello 
  <%= (request.getRemoteUser() != null? ", " + request.getRemoteUser() : "") %>
 !  I am DBBeanDemo JSP.
 </H1>
 <HR>
 <B> I`m using DBBean and i'm quering DEPT & EMP tables in schema SCOTT.....
    I get all employees who work in the Reasearch department.
 </B> 

 <P>
<%
    try {
 
      String sql_string = " select ENAME from EMP,DEPT " +
                          " where DEPT.DNAME = 'RESEARCH' " +
                          " and DEPT.DEPTNO = EMP.DEPTNO";

      // Make the Connection
      dbbean.connect();

      // Execute the SQL and get a HTML table
      out.println(dbbean.getResultAsHTMLTable(sql_string));

      // Close the Bean to close the connection
      dbbean.close();
    } catch (SQLException e) {
      out.println("<P>" + "There was an error doing the query:");
      out.println ("<PRE>" + e + "</PRE> \n <P>");
    }
%>

 </BODY>
</HTML>
