Updated on 2025-10-23 GMT+08:00

Loading a Driver

Load the com.mysql.jdbc.Driver database driver before creating a database connection.

You can load the driver in the following ways:

  • Implicit loading at any position before a connection is created in the code: Class.forName("com.mysql.jdbc.Driver");
  • During JVM startup, transfer its parameter java -Djdbc.drivers=com.mysql.jdbc.Driver jdbctest, where jdbctest indicates the test case program name.

For a driver of MySQL 8.0 or later, the package name is changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. When loading the driver, change the package name based on the driver version.