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 it DataSource
serves as a pool of connections to a database while DriverManager
only giving me one connection each time I ask for it. If it can be , I could use an in-depth answer on the subject.
DriverManager
is the class that allows you to loadDriver
database s and create connections to one or more databases. In Java SE, it is the only class that connects to the loaded drivers and gets a database connection. It does this using theDriver#connect
.DataSource
it is the interface that allows defining a pool of connections. What the implementations of this interface will do is create a pool of connections and they will be stored in a memory space (this is known as a pool). To create the connections, internally they make use ofDriverManager#getConnection
multiple times (1 per connection) or ofDriver#connect
and the configurations that have been loaded to create the instance ofDataSource
.