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

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");
主站蜘蛛池模板: 莱芜市| 长沙县| 洞口县| 昌乐县| 澄城县| 齐河县| 文水县| 平武县| 遵义县| 汝城县| 英吉沙县| 雷山县| 陵水| 东至县| 天长市| 广平县| 南木林县| 法库县| 南岸区| 连云港市| 皮山县| 黑龙江省| 南投县| 苗栗县| 皮山县| 始兴县| 赤壁市| 宁武县| 元朗区| 开远市| 高密市| 手机| 土默特左旗| 墨竹工卡县| 青海省| 大关县| 娱乐| 乌鲁木齐县| 盐池县| 辽源市| 康乐县|