官术网_书友最值得收藏!

Automatic SQL Driver Loading

JDBC 4.0 has facilitated the loading of a JDBC driver. In JDBC 3.0, a JDBC driver is loaded with the Class.forName(String) method. The Oracle JDBC driver is loaded in the following manner:

Class.forName("oracle.jdbc.OracleDriver");

In JDBC 4.0, a JDBC driver is loaded automatically with the Java Standard Edition Service Provider mechanism. The JDBC driver is loaded when the java.sql.DriverManager.getConnection() method is invoked. To load a JDBC driver with the Service Provider mechanism, JDBC 4.0 drivers should include the META-INF/services/java.sql.Driver file. In the java.sql.Driver file, specify the JDBC driver class to load. If the oracle.jdbc.OracleDriver is to be loaded then specify the following line in the java.sql.Driver file:

oracle.jdbc.OracleDriver

Multiple driver classes can be specified in a java.sql.Driver file, each on a separate line. A list of JDBC drivers available to a DriverManager can be obtained with the getDrivers() method:

Enumeration<Driver> drivers=DriverManager.getDrivers();

A JDBC connection can be obtained using the getConnection() method of the DriverManager class:

String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection connection = DriverManager.getConnection(url,"oe", "pw");
主站蜘蛛池模板: 泰州市| 黄冈市| 区。| 福贡县| 弥渡县| 灵宝市| 科技| 中方县| 南郑县| 沙洋县| 勃利县| 白河县| 都匀市| 三都| 通山县| 鄂伦春自治旗| 中山市| 长沙县| 田林县| 二手房| 改则县| 渑池县| 乌兰察布市| 如皋市| 瓮安县| 清水河县| 阿瓦提县| 邵阳市| 茶陵县| 双柏县| 大宁县| 文成县| 阿尔山市| 朝阳县| 东宁县| 鄂伦春自治旗| 分宜县| 廊坊市| 都兰县| 府谷县| 商河县|