JDBC connection

There are two main ways to get a Connection: DriverManager or DataSource. 
The DriverManager class looks through the classpath for JARs that contain a Driver. DriverManager knows that a JAR is a driver because the JAR contains a file called java.sql.Driver in the directory META-INF/services. Inside the java.sql.Driver file is one line. It is the fully qualified package name of the Driver implementation class.
State  | JDBC <= 3.0 Driver | JDBC >= 4.0 Driver
------ | ------ | ------
Required to contain java.sql.Driver | No | Yes
Java will use java.sql.Driver file if present | Yes | Yes
Required to use Class.forName | Yes | No
Allowed to use Class.forName | Yes | Yes

A Connection is created using a static method on DriverManager. It does not use a constructor. Do not use a DriverManager in code someone is paying you to write. 
```
public static void main(String[] args) throws SQLException, ClassNotFoundException {
  Class.forName("org.postgresql.Driver");
  Connection conn = DriverManager.getConnection(
    "jdbc:postgresql://localhost:5432/ocp-book",
    "username", "password");
}
```
A DataSource is a factory, and it has more features than DriverManager.