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

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");
主站蜘蛛池模板: 海口市| 玉环县| 九台市| 思茅市| 固镇县| 乐山市| 育儿| 民乐县| 云霄县| 洪湖市| 旬邑县| 岳普湖县| 三河市| 河津市| 同江市| 定南县| 汨罗市| 炉霍县| 商丘市| 福泉市| 安阳市| 五原县| 福清市| 巢湖市| 长寿区| 荣成市| 左权县| 古蔺县| 杨浦区| 罗城| 思茅市| 繁昌县| 巴楚县| 泌阳县| 陇西县| 明水县| 海南省| 沾化县| 临泽县| 平陆县| 嫩江县|