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

前端 未结 7 801
轮回少年
轮回少年 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:40

    This is used for to open a class or in other words invoke it via its name from string format.
    For example:

    Class.forName("com.android.example.MainClass");
    

    And it will start the class inside the package com/android/example/MainClass.java

    0 讨论(0)
提交回复
热议问题