permaculture playing cards*
The moose likes JDBC and the fly likes DriverManager vs DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "DriverManager vs DataSource" Watch "DriverManager vs DataSource" New topic
Author

DriverManager vs DataSource

Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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.
Thanks
Pho


Regards,

Pho
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

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
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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).]
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

http://www.codestudio.com/
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Many thanks! That looks like an impressive piece of work. It's far more ambitious than Struts' GenericDataSource. And its DataSource can be bound in a JNDI tree too. If it's robust, go for it.
- Peter
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DriverManager vs DataSource
 
Similar Threads
retrieving records from the database
Setting Connection Time Out
Registering driver with DriverManager
unmanaged javax.sql.DataSource
register Driver