Use session-scoped JavaBeans to improve the performance of
SQL queries.
Remarks
This sample extends the "Database
Access Using SQLJ" sample. It shows how to use a Session-Scoped JavaBean
to get the benefits of the SQLJ statement-caching feature of OC4J JSP.
The Session-Scoped JavaBeans feature preserves the state
of a variable across an HTTP Session. The Bean implements a special interface
called HttpSessionBindingListener to enable the use of a Bean in
the session scope. The scope attribute in the
tag defines the scope of a Bean.
Here, a session variable maintains the database connection
across requests from the same session. Using the same database connection for
all the requests within a HTTP session improves application performance by eliminating
the need to close a connection and restart it between requests.
Code from CountriesSqlj.jsp
<FORM> <% // Call the SqljQuerySessionBean which has the Database Access Logic // to display the List of All Countries %> <jsp:useBean class="SqljQuerySessionBean" id="SessionBean" scope="session" /> <jsp:setProperty name="SessionBean" property="CountryId" value="0" /> <%= SessionBean.displayResults() %> </FORM>