RAJ K RAJ K - 1 year ago 77
Java Question

Alternative way to load DB driver in Java

Is there any other way to load DB driver than class.forName?

Answer Source

Modern JDBC drivers are supposed to provide enough metadata in their jar file manifest, so you may not need to do anything.

The main point of Class#forName is to remove the compile-time dependency on the particular JDBC driver (and make it configurable at run-time). If you are using Oracle driver code in your program anyway (to use their non-standard JDBC extensions) and have no compulsions to hardcode the driver class name, you can also just create a regular instance of the driver class.

 new oracle.jdbc.driver.OracleDriver();