3

Suppose user having multiple drivers installed in their system like MySQL Connector/J Driver, PostgreSQL Driver , etc. For registering the driver we use forName() method of 'Class' class is used to register the driver class. This method is used to dynamically load the driver class.
For Example :-

Class.forName(DRIVER_NAME);

Is there any way we can use multiple drivers, something like this :-

if (AS/400 Toolbox Driver) :: Class.forName("com.ibm.as400.access.AS400JDBCDriver");
else
if(Attunity Driver) :: Class.forName("com.attunity.jdbc.NvDriver");
else
if(MySQL Connector/J Driver) :: Class.forName("com.mysql.jdbc.Driver");

so that we can give more flexibility to developers to choose between installed drivers.

Vipertecpro
  • 3,056
  • 2
  • 24
  • 43

1 Answers1

4

Registering JDBC drivers has not been necessary since the release of Java 6 and JDBC 4.0

Provided that the required jar based driver implementation is on the class path, JDBC will select the correct driver based upon the connection URL.

More information is available in the answer provided in How is driver class located in JDBC4.

Community
  • 1
  • 1
Steve C
  • 18,876
  • 5
  • 34
  • 37
  • Wow that's a bunch of knowledge at once.Thank you sir for leading me to this knowledge, recently i'm working on my project which is in java (for coding) and javafx (for GUI) , Goal is to create Admin Panel which helps to manage Server Side(localhost) of the Desktop Application. For Example you are working on a project which needs database for storing information(Username,UserID,...), Generally we prefer XAMPP(phpmyadmin),ORACLE,etc. I want through my java application(exe) all the drivers/softwares can be managed from one front-end.I would be glad if you give me any suggestion. – Vipertecpro Aug 30 '16 at 08:02
  • if registering driver is not necessary then what we will pass in class.forName(......) arguments here.And what will it return. – Vipertecpro Aug 30 '16 at 08:23