This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Originally posted by Pho Tek: What is the pros/cons for using DriverManager versus javax.sql.DataSource to obtain a JDBC connection ? I have been using DriverManager method for quite a while now.
DriverManager is just that: a thin manager class for raw jdbc drivers. A DataSource is both more abstract and more powerful: it is a place where you get your database connections from. This means a couple of things. It means that a DataSource can usually be configured and managed by the application server instead of your application. It means that the connections you get from a DataSource can come from a connection pool for performance. It means that the connections may participate in a container-managed distributed transaction without you having to worry about the nitty gritty of it. And even if your environment doesn't support DataSources, given that org.apache.struts.util.GenericDataSource can convert any old JDBC driver into a pooled DataSource I don't see why anyone would still want to use a DriverManager and a proprietary connection pool - Peter
Thanks. I had a look at the javadoc for GenericDataSource. It seems to have a serious limitation.
Generic data source implementation of the DataSource interface. WARNING - This implementation does not know how to provide connections with different username/password combinations..
Do you consider poolman a proprietary connection pooling framework ? Pho [This message has been edited by Pho Tek (edited November 08, 2001).]
Peter den Haan
Joined: Apr 20, 2000
Originally posted by Pho Tek: I had a look at the javadoc for GenericDataSource. It seems to have a serious limitation.
True. For most web applications, this isn't a limitation. Unless I'm missing something, forcing each user to have his own database-level identity mostly defeats the purpose of having a connection pool anyway; in n-tier environments this is rarely done. Authentication and authorization is enforced in one of the middle tiers instead. I don't know poolman, but I personally consider anything that doesn't expose a DataSource interface proprietary and obsolete. - Peter [This message has been edited by Peter den Haan (edited November 09, 2001).]