
<%@ 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; %>
<%@ include file="../checkConn.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:useBean>
<jsp:setProperty name="dbbean" property="URL" value="<%= connStr %>"  />
<% session.setAttribute("dbbean", dbbean); %>
<HTML> 
  <HEAD> 
    <TITLE>
	DBBeanDemo JSP
    </TITLE>
  </HEAD>
 <BODY BGCOLOR=EOFFFO> 
 <H1> Hello 
  <%= (request.getRemoteUser() != null? ", " + request.getRemoteUser() : "") %>
 !  I'm General Database Bean Demo JSP.
 </H1>
 <HR>
 <B> I'm using a bean for database access and I'm querying the DEPT and EMP tables in schema SCOTT.
     I get all employees who work in the Research department.
 </B> 

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

      // 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>
