wood burning stoves 2.0*
The moose likes JDBC and the fly likes COnnection from DriverManager and 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 "COnnection from DriverManager and DataSource" Watch "COnnection from DriverManager and DataSource" New topic
Author

COnnection from DriverManager and DataSource

Glen Cai
Ranch Hand

Joined: Aug 24, 2002
Posts: 121
Are the Connection objects obtained from DriverManager and
DataSource the same?


"I, a universe of atoms, an atom in the universe." - Richard Feynman
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You'll need to define 'the same'.
In theory you can usem both the same and they will behave the same, but only if they are using the same Driver library to provide Connections. They might not be.
Also, a DataSource usually hides a Connection Pool as well, where you get a new Connection each time from the DriverManager.
Karan V Praba
Ranch Hand

Joined: Oct 31, 2002
Posts: 41
Hai David O'Meara ,
Could you explain where have to use TXDataSource and DataSource..?


Karan V Praba.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

From a quick search, DataSource is a common J2EE thing, TXDataSource is a Weblogic thing. For more info on using TXDataSource, see this link It's specific to Weblogic 5.1, but should define the difference.
Weblogic uses them as properties to distinguish between DataSources that do and do not support Transactions. From what I see, TXDataSource is a property and not a Class or Interface. javax.sql.DataSource is an Interface used to describe interaction 'something that will give you a Connection to the databse'
Dave
Karan V Praba
Ranch Hand

Joined: Oct 31, 2002
Posts: 41
Hai David O'Meara,
Thanks a lot for your explaination.
Still I have one more doubt.Instead of getting the connection from DataSoruce We could get it from JNDi name of connectionPool ,isn't it.?
What is primary goal of to using DataSoruce..?
Please clear me with some example.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Not quite right.
You get the DataSource from JNDI, then you get a Connection from the DataSource.
J2EE is based on the idea of having services that are supplied by an application server that applications can make use of. This also includes the requrement to create scaleable and distributable applications. If you have applications obtaining their own database connections, there is no maintain dtabase resources, and there are other problems like how much code do you have to rewrite if you swap database vendors, how do you configure other things that need database support (like session persistence) etc
A DataSource is a generic 'applications that run on an application servers can get Connections from here' place. Then any extra responsibility that the The DataSource needs to do (like pooling, keeping Connections alive, sharing between multiple applications) can all be done invisibly to the individual applications. All you know is that you can get Connections easily, efficiently and safely, and so can any other application running on the server.
Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Oh, and we seem to have hijacked Glen's original thread. Appologies, Glen
Karan, it is usually a better idea to start a new thread for a new question that is not related to the previous one!
Dave
Glen Cai
Ranch Hand

Joined: Aug 24, 2002
Posts: 121
It is Ok. David.
I think the close() method is not the same on
the Connection objects from DriverManager and
DataSource.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: COnnection from DriverManager and DataSource
 
Similar Threads
DriverManager vs Datasource
diff between java.sql.* and javax.sql.*?
query about rowset
java.sql.SQLException: No suitable driver
Data Sources