JDBC use the way of registry to manage its drivers by the method of
This method is static one, usually there’re several ways to invoke it:
- in your code, write
Class.forName("com.xx.jdbc.Driver");, this is a way to load the specified
Driverclass explicitly. You can get the effect because the jdbc driver venders usually get the
registerDriver(..)method invoked just in the static block of the
- you can tell the JVM to load which driver by setting the
- Another way is supported by the
ServiceLocatormode. This needs the jdbc driver vender to package their jdbc driver jar following the service provider convention.
If you see the source code of JDBC API, you will find that the behaviours of way 2) and 3) are defined by the
DriverManager.loadInitialDrivers() static method. So you needn’t do anything in your code to register
- DB2 JDBC driver
db2jcc4.jaris packaged following the service provider convention, so you needn’t invoke
Class.forName(..)in your code.
- MySQL JDBC driver
mysql-connector-java.jaruses the same way.