I am trying to get an accurate understanding of how Java's Service Provider Mechanism works to locate the appropriate JDBC driver. Here is what I have so far:
Since Class.ForName
is no longer used to explicitly load a JDBC Driver
, Java would know what type driver it needs from the database url string that one passes to the getConnection
method. For instance the database url to connect to a oracle database would be something like this:
public static final String DB_URL = "jdbc:oracle:thin@//localhost:1521/ORCL";
The DriverManager
would then look for implementation of oracle driver in the jars specified in the projects class path. It would look for the drivers configuration files (in which would be the name of actual driver classes) in META-INF/Services
directory of each jar. The Class Loader
will load the very first match that it finds and ignore the rest.
Is the above working accurate ? Please let me know If I missed something or got something wrong.