Vaibhav G Garg wrote:i. Why do we need to load the driver class using this statement?
Part of the pre-jdbc 4.0 api. The class has a static piece of code to register itself. When a class is loaded in
Java, static methods are executed by the VM as part of the load activity.
You load the class -> The class runs its static methods -> Driver registered
Vaibhav G Garg wrote:ii. Can't we include the driver class on our classpath and hence, can be loaded during the application startup itself along with other classes?
From jdbc 4.0 on: yes. Pre-jdbc 4.0: no, because putting these drivers in the classpath didn't run their registration static code.
Vaibhav G Garg wrote:iii. What is the benefit we do achieve using this statement in our code?
Pre-jdbc 4.0 only:
The driver registers itself.
and when you open a jdbc connection in your program, the jdbc api will iterate over all its registered drivers, and will give the task to connect to the first one that recognizes the connection
string.