tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phillip Morelock <>
Subject Re: Connection Pooling Solution
Date Thu, 30 May 2002 20:28:25 GMT
javax.sql.DataSource itself is not returning Connections.

DataSource is an interface -- what this means in practice is that some
random class (in this case, BasicDataSource) is implementing that interface.
You're actually asking that class for a Connection, and you "know" that you
can call any method on it that is defined in javax.sql.DataSource because it
implements that interface.  So while your code might hypothetically look
like (partially pseudo-code):
BasicDataSource bds = Somewhere.getDataSourceObject();
Connection conn = bds.getConnection() ;

it's far more flexible to do this:
DataSource ds = Somewhere.getDataSourceObject();
Connection conn = ds.getConnection();

If you get another database connection pool (say, from MS or Oracle or
something) and you want to change the actual class for the DataSource (say,
now it's "MSSQLServerDataSource" or whatever) -- as long as that next class
still implements the javax.sql.DataSource interface, you can still work with
it without changing any of your code, just the config file that tells Tomcat
which DataSource class to use.

So all you would do if you have to change databases or driver classes, is
change web.xml or server.xml or wherever you have the driver / data source
class configured, and all your code can remain using "DataSource" as the
type of the object, no changes from "BasicDataSource" to
"MSSQLServerDataSource" all over the place.

Is this clear?


On 5/30/02 1:21 PM, "Cindy Ballreich" <> wrote:

> At 03:43 PM 5/30/02 -0400, Rick Fincher wrote:
>> Because the MySql driver is a javax.sql.DataSource and that's what gets
>> passed back by the pool, making the pool transparent (no pun intended).
>> That way you can later change the driver or the pooling details without
>> changing your code (assuming the SQL dialect still works).
>> Rick
> Thanks for replying Rick,
> I may have run up against a gap in my java knowledge, but I don't understand
> your answer. I guess I don't see how javax.sql.DataSource can get (and return)
> connections from the pool. It doesn't seem like it would have the ability to
> do that. Isn't BasicDataSource just an implementation of DataSource? Is DBCP
> pooling DataSources?? Am I completely clueless here?
> Also, since the driver is being called from the resource factory (using
> BasicDataSourceFactory), I'm not sure I understand why using BasicDataSource
> to get connections would affect the driver at all?
> Thanks again!
> Cindy
> --
> To unsubscribe, e-mail:   <>
> For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message