You should be using some type of data source or preferrably a
connection pool based on a data source. Most web servers include a
connection pool implementation and all that's needed is to define the
connection pool, define the data source, and then link the two. Your
web app will then get a connection from the connection pool when
needed, and release it when finished. There is not much overhead when
using a connection pool as the connections are created once and then
passed around to whomever needs them. You can also specify how many
concurrent connections to the database the connection pool contains.

Regardless of implementation, each request should be getting and
releasing it's own connection, not sharing them between requests as
your question seems be saying. If you are sharing a single connection,
you will have multiple requests in your web application using the same
connection object, which is not allowed and will cause you problems at
some point. Since threads are non-deterministic, these errors will be
mysterious, hard to duplicate, and very difficult to debug. See
http://en.wikipedia.org/wiki/Race_condition#Computing

-ed

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]
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to