Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading JDBC driver without Class.forName

Tags:

java

jdbc

The Oracle JDBC tutorial says

In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method Class.forName. This methods required an object of type java.sql.Driver. Each JDBC driver contains one or more classes that implements the interface java.sql.Driver. The drivers for Java DB are org.apache.derby.jdbc.EmbeddedDriver and org.apache.derby.jdbc.ClientDriver, and the one for MySQL Connector/J is com.mysql.jdbc.Driver. See the documentation of your DBMS driver to obtain the name of the class that implements the interface java.sql.Driver.

Any JDBC 4.0 drivers that are found in your class path are automatically loaded. (However, you must manually load any drivers prior to JDBC 4.0 with the method Class.forName.)

But when I remove Class.forName it gives an error No Driver found. I am using ojdbc14 driver. How do we implement connection without Class.forName?

like image 715
Abhishek kumar Avatar asked Apr 19 '26 21:04

Abhishek kumar


1 Answers

Look closely at the JDBC version. The article says that it's introduced in JDBC 4.0 (Java 1.6).

However, ojdbc14 is a JDBC 3.0 (Java 1.5) driver.

like image 132
BalusC Avatar answered Apr 21 '26 11:04

BalusC