In Java what is the difference between DriverManager.g etConnection()
and DataSource.getC onnection()
Regards,
gantijagadeesh.
Connection object got from Datasource.getC onnection() ,when closed will be returned back to connection pool..but will not be closed permanently
whereas Connection object retrieved from DriverManager.g etConnection() when closed will be returned permanantly..
so..i mean to say connection pool will be used for managing connections in case of DataSource. Connection pool is nothing but a pool of connection objects, from which u can retrieve connections to more than one database
as and when required and can be returned to pool..instead of permanantly closing it...so retrieving the connection object is faster in case of DataSource..
Hi Friend,
In both ways we can get the connection, DriverManager and DataSource.
One difference between both is that Datasource has properties with it, which represents the Source of data it represents.
Other is, DataSource supports the JNDI Service, so we can give any logical name to that datasource eg. MSSQLDataSource to MS SQL server,
MySQLDataSource to MySQL.
One more is, DataSource can be separately created and managed and can be accessed from any of the Application through lookup facility of JNDI.
DataSource is the standard interface in JDBC, which need to be implemented by database Driver, can be implemented to maintain the pool of connections.
Comment