Newbie: Where to put instance for database access?

2005-07-06 Thread Peter . Zoche
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

RE: Newbie: Where to put instance for database access?

2005-07-06 Thread Marco Mistroni
Should it be stored in the ServletContext for application scope? But how do I access this instance from my Actions? getServlet().getServletContext().getAttribute(xxx) Or would it be better to use data-sources? If I should use them, does anybody know a good tutorial on the internet? Perhaps

AW: Newbie: Where to put instance for database access?

2005-07-06 Thread Peter . Zoche
Should it be stored in the ServletContext for application scope? But how do I access this instance from my Actions? getServlet().getServletContext().getAttribute(xxx) is it the same as request.getSession().getServletContext().getAttribute(xxx) ? Peter

Re: AW: Newbie: Where to put instance for database access?

2005-07-06 Thread Stéphane Zuckerman
[EMAIL PROTECTED] a écrit : Should it be stored in the ServletContext for application scope? But how do I access this instance from my Actions? getServlet().getServletContext().getAttribute(xxx) is it the same as request.getSession().getServletContext().getAttribute(xxx) ? Yes. --

RE: Newbie: Where to put instance for database access?

2005-07-06 Thread Jesse Alexander (KBSA 21)
Yes. Check with servlet-APIdoc... Alexander -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 06, 2005 11:10 AM To: user@struts.apache.org Subject: AW: Newbie: Where to put instance for database access? Should it be stored in the ServletContext

Re: Newbie: Where to put instance for database access?

2005-07-06 Thread Aleksandar Matijaca
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

Re: Newbie: Where to put instance for database access?

2005-07-06 Thread Ed Griebel
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

Re: Newbie: Where to put instance for database access?

2005-07-06 Thread BHansard
to Struts Users Mailing List user@struts.apache.org To Struts Users Mailing List user@struts.apache.org cc Subject Re: Newbie: Where to put instance for database access? Create a singleton class, that holds the instance of a connection in a ThreadLocal class in that singleton