MCQ: Which methods are required to load a database driver in JDBC?

Which methods are required to load a database driver in JDBC?

  1. getConnection()
  2. registerDriver()
  3. forName()
  4. Both b and c

Answer

d. Both b and c

Explanation:

There are two ways to load a database driver in JDBC:
  • By using the registerDriver() Method: To access the database through a Java application, we must register the installed driver in our program. We can do this with the registerDriver() method that belongs to the DriverManager class. The registerDriver() method takes as input a driver class, that is, a class that implements the java.sql.Driver interface, as is the case with OracleDriver.
  • By using the Class.forName() Method: Alternatively, we can also use the forName() method of the java.lang.Class to load the JDBC drivers directly. However, this method is valid only for JDK-compliant Java virtual machines. It is invalid for Microsoft JVMs.

Comments