我们是否可以添加多个sql驱动程序,如OTD、MySQL Connector/J、PostgreSQL、SyBase JConnect等等?

时间:2021-12-21 16:24:59

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 :-

假设用户在其系统中安装了多个驱动程序,如MySQL Connector/J Driver、PostgreSQL Driver等。为了注册驱动程序,我们使用“类”类的forName()方法来注册驱动程序类。该方法用于动态加载驱动程序类。例如:-

Class.forName(DRIVER_NAME);

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.

这样我们就可以给开发人员更大的灵活性来选择安装的驱动程序。

1 个解决方案

#1


4  

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

自从Java 6和JDBC 4.0发布以来,没有必要注册JDBC驱动程序

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

如果基于jar的驱动程序实现位于类路径上,JDBC将根据连接URL选择正确的驱动程序。

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

在JDBC4中的驱动程序类中提供了更多的信息。

#1


4  

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

自从Java 6和JDBC 4.0发布以来,没有必要注册JDBC驱动程序

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

如果基于jar的驱动程序实现位于类路径上,JDBC将根据连接URL选择正确的驱动程序。

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

在JDBC4中的驱动程序类中提供了更多的信息。