While doing a simple JDBC connection, all the resources gives the same code that
String driver = "com.mysql.jdbc.Driver";
Statement statement = null;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url + dbName,userName, password);
But we actually nothing do with "Class.forName(driver)". We didn't stored it anywhere. What is the use of that as we nothing do with Class.forName(driver)'s return.
Class.forName()
attempts to load the named class. In early versions of JDBC, this was necessary as the Driver
class required the class to be loaded in this way. This hasn't been required for ages.
Leave out the call and nothing bad will happen.
For some reason, tutorials and examples persist with the old way.
The only tiny benefit of loading the class manually is that it tells you exactly what the problem is in case you haven't got the right class in the classpath.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With