I’ve seen this type of code quite a bit in code which initializes the MySQL JDBC connection.
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://10.0.0.2:3306", "username", "password");
Now my question is why/when is this first line required? I’ve been able to connect without any problems to a MySQL database by just having this:
conn = DriverManager.getConnection("jdbc:mysql://10.0.0.2:3306", "username", "password");
I’m using Java 7 with the Connector/J 5.0.8 driver.
I don’t have any import or class loading statements in my code which would directly load the MySQL driver, only the generic Java SQL interface classes.
Short answer : With JDBC drivers prior 4.0 (JDBC 4.0 introduce auto-loading of JDBC driver class)
Source: JDBC Basics