FileDocCategorySizeDatePackage
CachedConnectionServlet.javaAPI DocExample1877Mon Jun 18 20:33:58 BST 2001None

CachedConnectionServlet

public class CachedConnectionServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


    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>");
  
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

    doGet(request, response);