Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2004

Tip: Looking for answers? Try searching our database.

Connection Pooling for multiple JSP's

Thread view: 
Robert Kattke - 17 Jan 2004 07:04 GMT
I'm designing a jsp page that will include up to 8 other jsp's, each
with their own bean, requiring a DB connection.

I had seen an Enterprise Servlet example, that created a static DBPool
in the init() method.   There were obvious performance benefits, but
I'm not sure how to reap the same benefits with multiple JSP pages.  
New Strategy ?

Can I create a static Pool in  _jspInit()  and let other jsp/bean have
access to it with checkIn(), checkOut() methods ?
Would the Pool need to be added as an Attribute to the session or
application?

Strategies and Snippets, much appreciated.   TIA -R
Oscar Kind - 17 Jan 2004 09:59 GMT
> I'm designing a jsp page that will include up to 8 other jsp's, each
> with their own bean, requiring a DB connection.
[quoted text clipped - 10 lines]
>
> Strategies and Snippets, much appreciated.   TIA -R

You may want to consider creating a factory class for database
connections. I'd suggest a singleton that initializes a data source or
connection pool on initialization and then provides a facade to it (i.e.
it implements methods with the same or similar names to the methods in the
datasource that simply call the corresponding methods from the datasource).

The compiled class goes into WEB-INF/classes (in the directory of its
package), and can be used from JSP's.

For example:
- The class is nl.opk.test.DataSourceFacade and contains at least the
 public static method getInstance().
- Then the JSP can then use it thus:
    <%@ page language="java" %>
    <%@ page import="nl.opk.test.DataSourceFacade" %>

    <%
        DataSourceFacade dsf = DataSourceFacade.getInstance();
    %>

Notes:
- Use a singleton to ensure the different JSP's use the same datasource /
 connection pool.
- You probably want the method getInstance to read a properties file that
 defines the connection to the database. I'd suggest a ResourceBundle
 that reads the resources from "nl.opk.test.Database", so you can place a
 file "Database.properties" in the same directory as the class. The
 .properties file contains comments (empty lines and lines beginning with
 a hash (#)), and <name>=<value> pairs.

Oscar

Signature

No trees were harmed in creating this message.
However, a large number of electrons were terribly inconvenienced.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.