Since Java 1.6, JDBC 4.0 API, it provides a new feature to discover java.sql.Driver automatically, it means the Class.forName is no longer required. Just put any JDBC 4.x driver in the project classpath, and Java is able to detect it.

For example, JDBC driver for PostgreSQL:



And it works:

package com.mkyong.jdbc;

import java.sql.*;

public class JDBCExample {

    public static void main(String[] args) {

        try {

            // this is optional @since 1.6
            // Class.forName("org.postgresql.Driver");

            // auto close connection
            try (Connection conn =
                                 "postgres", "password")) {

                Statement statement = conn.createStatement();


        } catch (Exception e) {
            System.err.println("Something went wrong!");