Difference between DataSource and DriverManager

1

As the title says, I want to know what is the difference between DataSource and DriverManager in a web application using Tomcat. So far I know that DataSource serves as a pool of connections to a database while DriverManager only gives me a connection every time I ask. If it can be , I could use an in-depth answer on the subject.

    
asked by MatiEzelQ 19.09.2016 в 21:02
source

1 answer

1

DriverManager is the class that allows you to load the < a href="https://docs.oracle.com/javase/8/docs/api/java/sql/Driver.html"> Driver s database and create connections to one or more databases. In Java SE, it is the only class that connects with the loaded drivers and obtains a database connection. This is done using the Driver#connect method.

DataSource is the interface that lets you define a pool of connections. The implementations of this interface, what they will do, will be to create a group of connections and they will be stored in a memory space (this is known as a pool). To create connections, internally use DriverManager#getConnection multiple times (1 per connection) or Driver#connect and configurations that have been loaded to create the instance of DataSource .

    
answered by 19.09.2016 / 22:30
source