What is the actual use of Class.forName(\"oracle.jdbc.driver.OracleDriver\")
while connecting to a database? Why cant we just import the same class, instead why
When we want to execute static block of a class, without creating its object then we can use class.forName()
. Most of the work that Driver
class do, exists in its static block.
Now what we require in our JDBC connectivity is to get the driver registered with DriverManager
and to obtain connections with it, so this can be achieved simply by getting static block executed and there is no requirement to create object of that class. This approach will give a better performance.