Re: Database Connection question



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
.



Relevant Pages

  • Re: Making a database connection global
    ... connection would be opened the same amount of time (which no-one yas yet ... Anyway, if he don't want to listen, a different angle will probably not ... to reference the database connection once. ... I created a class with a static database connection and the class opens ...
    (microsoft.public.dotnet.framework.aspnet)
  • Database Connection Question
    ... we were using an asp include file with database functions ... and would open and close the database connection multiple times in 1 script. ... I don't know, the persistent connection seems much better to me, easier to ...
    (microsoft.public.inetserver.asp.db)
  • Re: garbage collection
    ... it will get a reader back.. ... you can not reuse the connection on which it opened. ... > garbage collection issue, its a logical error. ... > on database connection is, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: simplifying repeating database connections in a class?
    ... I wrote my first PHP class today. ... >> repeat the database connection lines, ... That's why I'm calling the include twice, once in each function, ...
    (comp.lang.php)
  • RE: Activated Event Vs. other Events
    ... your function to check the database connection ... > The form has to render itself completely first, then attempt a connection, ... > I placed all related code in the Load event, just to realize this code gets ...
    (microsoft.public.dotnet.framework.windowsforms)