Depending on the level of usage to the database, I would recommend implementing a connection-pool and requesting a connection each time you need to query the database. If you hold a single connection for your application, you will limit your scalability and hurt performance based on the user load. How you set up this pool is dependent on the database you are using and the resources you have available to that database.
I would recommend looking at the Jakarta Commons-pool project. All of the major J2EE Appservers and most of the Java Servlet Container Servers support connection pooling. The only exception that I can think of off the top of my head is Sun iPlanet 6.0 or less. Tomcat will support connection pooling and has a decent how-to on their website.
Aleksandar Matijaca <[EMAIL PROTECTED]>
07/06/2005 03:01 PM
|
|
Create a singleton class, that holds the instance of a connection in a
ThreadLocal class in that singleton --
this way you don't have to keep stuff in the session...
Regards, Alex.
On 7/6/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I have maybe a simple question:
>
> My web-app has to get data out of a database. I have a class
> DatabaseHandler
> which
> holds a connection to the database and provides methods to query it. I
> would
> like to
> have only one instance of this class in my web-app. But I don't know where
> to put it.
> Should it be stored in the ServletContext for application scope? But how
> do
> I access
> this instance from my Actions? Or would it be better to use data-sources?
> If
> I should
> use them, does anybody know a good tutorial on the internet? Perhaps
> hibernate would
> be a good choice too, but I think its a bit oversized for my application.
> You see - I
> am a total newbie concerning the use of databases with struts. Please
> help!!!
>
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>