title: Produce a `DataSource` object for Postgres JDBC, programmatically
body: <p>The <a href="https://docs.oracle.com/javase/tutorial/jdbc/TOC.html" rel="noreferrer">JDBC Tutorial</a> recommends using a <a href="https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html" rel="noreferrer"><code>DataSource</code></a> object to obtain database connections rather than using the <code>DriverManager</code> class. To quote the <a href="https://docs.oracle.com/javase/tutorial/jdbc/basics/sqldatasources.html" rel="noreferrer"><em>Connecting with DataSource Objects</em></a> page:</p>
  
  <blockquote>
    <p><code>DataSource</code> objects … the preferred means of getting a connection to a data source.</p>
  </blockquote>
  
  <p>How do I get such an object for a <a href="https://en.wikipedia.org/wiki/JDBC" rel="noreferrer">JDBC</a> connection to Postgres? I have a JDBC driver in place.</p>
  
  <p>Right now, I do not want to fiddle around with JNDI like <a href="https://stackoverflow.com/q/3461310/642706">this</a> or <a href="https://stackoverflow.com/q/32581833/642706">this</a>. </p>
  
  <p>Can I instantiate a <code>DataSource</code> programmatically within my Java app? Or must I implement that <code>DataSource</code> interface myself?</p>