Why we use Class.forName(“oracle.jdbc.driver.OracleDriver”) while connecting to a database?

前端 未结 7 812
轮回少年
轮回少年 2020-11-30 01:41

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

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 02:21

    Class.forName(“oracle.jdbc.driver.OracleDriver”) takes the class name as a string argument and loads it into memory. Second way of loading a class is to simply creating an instance of it using new. Disadvantage of second method is the newly created instance will be of no use if you don't need it.

    There is a nice tutorial explains JDBC connection basics.

提交回复
热议问题