Intermediate JSP Sample : Using Connection Pooling

Previous Contents Next

Contents

Purpose

Use the Connection Pooling feature available in JDBC.

Remarks

Connection pooling is a mechanism whereby when an application closes a connection, that connection is recycled rather than being destroyed. Because establishing a connection is an expensive operation, reusing connections can improve performance dramatically by reducing the number of new connections that need to be created. Connection pooling is especially useful in Middle Tier layers.

To demonstrate this feature, this example implements ConnectionPoolingBean, called from JSPs in a middle tier. The JSPs render the UI, and invoke the JavaBean to reserve and canel hotel rooms.

Also, this example uses the JML tags available with OC4J JSP. Many of the JML tags are intended to simplify coding syntax for JSP developers who are not proficient with Java. This example uses JML tags to execute certain code blocks only when certain conditions are met.

Code from CancelBookings.jsp

  <jml:setProperty name="connPool" property="hotelId"
value="<%= request.getParameter(\"HOTEL_ID\") %>" />
<jml:setProperty name="connPool" property="reqType"
value="<%= request.getParameter(\"REQ_TYPE\") %>" />
<jml:choose>
<jml:when condition = "<%= connPool.getReqType().toUpperCase().equals(\"CANCEL_FORM\") %>" >
<%--
If the value of the parameter REQ_TYPE is "CANCEL_FORM" then,
display the existing bookings for the user to select one and submit.
--%>
<FORM onSubmit="return validatecancel()">
<CENTER>
<%= connPool.getBookings() %>
<INPUT type=button value="Close" onClick="window.close();">
<INPUT type=hidden name="HOTEL_ID" value=<%=connPool.getHotelId()%>>
<INPUT type=hidden name="REQ_TYPE" value="">
<INPUT type=hidden name="BOOKING_ID" value="">
</CENTER>
</FORM>
</jml:when>
<jml:when condition = "<%= connPool.getReqType().toUpperCase().equals(\"DO_CANCEL\") %>" >
<%--
If the value of the parameter REQ_TYPE is "DO_CANCEL" then,
call the bean method to delete the booking from the database.
--%>
<FORM>
<BR>
<% String l_bookingId = request.getParameter("BOOKING_ID"); %>
<%= connPool.cancel(l_bookingId) %>

<BR>
<CENTER>
<INPUT type=SUBMIT value="Back">
<INPUT type=button value="Close" onClick="window.close();">
<INPUT type=hidden name="REQ_TYPE" value="CANCEL_FORM">
<INPUT type=hidden name="HOTEL_ID" value=<%=connPool.getHotelId()%> >
<INPUT type=hidden name="BOOKING_ID" value="">
</CENTER>
</FORM>
</jml:when>
</jml:choose>

 

Source Code Listings


Previous Contents Next
E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy