JDBC – Load Driver

Class.forName():

  • The most common approach to register a driver is to use Java’s Class.forName() method.
  • Class.forName() method is to dynamically load the driver’s class file into memory, which automatically registers it.
package online;
public class LoadDriver
{
            public static void main(String args[])
            {
                        String driver = “oracle.jdbc.driver.OracleDriver”;
                        try
                        {
                                    Class.forName(driver);
                                    System.out.println(“Driver loaded”);
                        }
                        catch(ClassNotFoundException e1)
                        {
                                    System.out.println(“Exception : Driver is not present”);
                        }
            }
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top