response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Cached Connection Servlet</title>");
out.println("</head>");
out.println("<body>");
// let's turn on verbose output
CacheConnection.setVerbose(true);
// now let's get a cached connection
Connection connection = CacheConnection.checkOut();
Statement statement = null;
ResultSet resultSet = null;
String userName = null;
try {
// test the connection
statement = connection.createStatement();
resultSet = statement.executeQuery(
"select initcap(user) from sys.dual");
if (resultSet.next())
userName = resultSet.getString(1);
}
catch (SQLException e) {
out.println("DedicatedConnection.doGet() SQLException: " +
e.getMessage() + "<p>");
}
finally {
if (resultSet != null)
try { resultSet.close(); } catch (SQLException ignore) { }
if (statement != null)
try { statement.close(); } catch (SQLException ignore) { }
}
// let's return the conection
CacheConnection.checkIn(connection);
out.println("Hello " + userName + "!<p>");
out.println("You're using a cached connection!<p>");
out.println("</body>");
out.println("</html>");