DriverManager vs. DataSource?
From: hank barta (hbarta_at_comcast.net)
Date: 01/21/04
- Next message: Joe Weinstein: "Re: choices regarding where to place code - in the database or middle tier"
- Previous message: Daniel Morgan: "Re: choices regarding where to place code - in the database or middle tier"
- Next in thread: Lee Fesperman: "Re: DriverManager vs. DataSource?"
- Reply: Lee Fesperman: "Re: DriverManager vs. DataSource?"
- Reply: Oscar Kind: "Re: DriverManager vs. DataSource?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 21 Jan 2004 04:25:29 GMT
I've been working with some code that accesses a MySQL database with
plans to use it in some web applications (either servlets or JSPs.) I
started with some old code that uses the java.sql.DriverManager
class to establish the connection. Looking at some code in the
J2EE samples, it looks like (and I quote from the documentation)
"The use of a DataSource object is the preferred means of connecting
to a data source."
This leaves me with some questions.
Is it even possible to use DriverManager in a servlet or JSP? I
started looking at the documentation because I could not figure out
how to get my JSP to find mysql.jar.
Can I use DataSource in a console app? It looks like it requires a
JNDI server (again, according to the docs "An object that implements
the DataSource interface will typically be registered with a JNDI
service provider.") I presume that means that I need to run the
servlet/JSP container at a minimum to use a data source (whether
for a console app or JSP.)
I presume that once I have a Connection, it doesn't matter whether
it came from a DriverManager or DataSource, the behavior is pretty
much the same. Is that correct?
I would like to retain the capability to test my database code
from a console application rather than from within a JSP. Will
it be necessary to use different connection methods depending on
the environment or can I switch to the DataSource and use that in
both environments.
Finally, if these are routine questions that are answered somewhere,
please point me to that resource!
thanks,
hank
- Next message: Joe Weinstein: "Re: choices regarding where to place code - in the database or middle tier"
- Previous message: Daniel Morgan: "Re: choices regarding where to place code - in the database or middle tier"
- Next in thread: Lee Fesperman: "Re: DriverManager vs. DataSource?"
- Reply: Lee Fesperman: "Re: DriverManager vs. DataSource?"
- Reply: Oscar Kind: "Re: DriverManager vs. DataSource?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|