Re: Database Connection question
- From: Pete Barrett <petebarrett@xxxxxxxx>
- Date: Thu, 03 Nov 2005 19:19:30 +0000
On Wed, 2 Nov 2005 17:56:20 -0500, "JY" <jy1970us@xxxxxxxxx> wrote:
>I have 2 applications: one is using JBoss where the database connection is
>obtained through JNDI lookup; the other is a standalone app and is using
>java.sql.DriverManager for Connection. Every time after obtaining a
>Connection, a stored proc is called.
>My task is to write generic code for database connection to be used in both
>application. Please give some input on what should be the best way.
>
DriverManager will work from within JBoss; a JNDI lookup will only
work from outside if you have an InitialContext from somewhere; so the
only universal way to obtain a database connection is to use
DriverManager both within your bean (or servlet, or whatever), and in
the standalone application. But I can't beleive that that's an answer
to the question you had in mind, because you obviously know that
already.
What exactly do you mean by 'generic' code? All the database code will
be generic once the Connection is obtained, so what I usually do is to
centralise all the database access in a single class, and provide the
Connection in an open() method. Is that the sort of 'generic' code you
had in mind? (Obviously, there are other equally generic ways of doing
it apart from the way I prefer.)
Pete Barrett
.
- Follow-Ups:
- Re: Database Connection question
- From: JY
- Re: Database Connection question
- Prev by Date: Re: Problem closing resources using Apache HttpClient.
- Next by Date: Re: Why no compiler-warning at invalid array-initializing ?
- Previous by thread: trouble resolving a class with JSP
- Next by thread: Re: Database Connection question
- Index(es):
Relevant Pages
|