<%@ page language="java" contentType="text/html" import="java.sql.*"%>

<%
Connection conn;
ResultSet resultSet;
try {
    // Load the Oracle JDBC driver
    Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e) {
    System.out.println("Driver not found.");
    System.out.println(e.toString());
    throw new UnavailableException(this, "Class not found.");
}
try {
    // Connect to the Database
    conn = DriverManager.getConnection("jdbc:oracle:thin:@dbhost:1521:ORA1", "scott", "tiger");

    Statement statement = conn.createStatement();
    resultSet = statement.executeQuery("SELECT empno, ename, job,"
        + " NVL(TO_CHAR(mgr), '---') \"mgr\","
        + " TO_CHAR(hiredate, 'DD.MM.YYYY') \"hiredate\","
        + " NVL(TO_CHAR(sal), '0') \"sal\","
        + " NVL(TO_CHAR(comm), '0') \"comm\","
        + " RPAD(TO_CHAR(deptno), 6, ' ') \"deptno\""
        + " FROM emp order by ename");
}
catch(SQLException e) {
    System.out.println("An error occurs.");
    System.out.println(e.toString());
    throw new UnavailableException(this, "Cannot connect with the specified database.");
}
%>

<html>
<head>
<title>Access to Oracle9i Database on Akadias Site</title>
<link REL="stylesheet" HREF="https://www.akadia.com/docroot/css/website.css" TYPE="text/css">
</head>
<body>
<h1>Select * from EMP</h1>
<hr>
<pre>Connection settings:
  getAutoCommit = <%=conn.getAutoCommit()%>
  getCatalog = <%=conn.getCatalog()%>
  getTransactionIsolation = <%=conn.getTransactionIsolation()%>
  isClosed = <%=conn.isClosed()%>
  isReadOnly = <%=conn.isReadOnly()%>

</pre>
<p>Return result:</p>

<table border=1 cellpadding=2 cellspacing=0 width=500>
<% int countrows = 0; %>
<% while (resultSet.next()) { %>
<tr height="302">
    <td height="16"><%= resultSet.getString("empno") %></td>
    <td height="16"><%= resultSet.getString("ename") %></td>
    <td height="16"><%= resultSet.getString("job") %></td>
    <td height="16"><%= resultSet.getString("mgr") %></td>
    <td height="16"><%= resultSet.getString("hiredate") %></td>
    <td height="16"><%= resultSet.getString("sal") %></td>
    <td height="16"><%= resultSet.getString("comm") %></td>
    <td height="16"><%= resultSet.getString("deptno") %></td>
    <% countrows++; %>
</tr>
<% } %>
</table>
<p><%=countrows%> row(s) found.</p>
<hr>
<p><a href="database.txt" target="_top">Show JSP source</a></p>
</body>
</html>