tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cindy Ballreich <>
Subject Re: Connection Pooling Solution
Date Thu, 30 May 2002 21:05:49 GMT

At 01:28 PM 5/30/02 -0700, Phillip Morelock wrote:
>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?

Yes, much more so. Thanks! I was misunderstanding the whole relationship. I spent some time
going over the source for BasicDataSource and I think I'm much clearer on the whole thing.


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

View raw message