title: Why do we use a DataSource instead of a DriverManager?
body: <p>I am reading the Java JDBC specification (vr. 4) and I encountred this statement:</p>
  
  <blockquote>
    <p>DataSource — this interface was introduced in the JDBC 2.0 Optional
    Package  API. It is preferred over DriverManager because it allows
    details about the  underlying data source to be transparent to the
    application</p>
  </blockquote>
  
  <p>What I am trying to understand is what the difference is between a <a href="https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html" rel="noreferrer"><code>Connection</code></a> and a <a href="https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html" rel="noreferrer"><code>DataSource</code></a>, and why it exists. I mean, the block above says that the details about a datasource is transparent to the application, but wouldn't externalizing database properties such as username, password, url etc in a property file and then use DriverManager work in the same way?</p>
  
  <p>And is the <a href="https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html" rel="noreferrer"><code>DataSource</code></a> interface created only to have a common way of returning connections that can be pooled etc? In Java EE, does the application server implement this interface and the applications deployed to have a reference to a datasource instead of a connection?</p>