--> I have read that Class.forName() is to load the class dynamically. --> And one of the places it is used is to load the Driver in jdbc. --> for e.g. --> Class.forName("com.mysql.jdbc.Driver");
Normally what you will do is have the driver in a properties file and then call Class.forName(myDriverProperty); That way by changing the value in the properties file you will be loading a different jdbc driver
--> But instead of the above code can i just use --> package com.mysql.jdbc.Driver;
I think you mean import com.mysql.jdbc.Driver ??
so what do you do if you now want to use a postgres database driver. You have to change and recompile your code to now import org.postgresql.Driver.
--> Why do i need to use Class.forName() (i.e. load it dynamically); That's exactly why you need Class.forName(). To load the class dynamically. IE: No recompile necessary if you change databases.