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

DriverManager Class

The DriverManager class is used to obtain a connection with a database. A JDBC driver is required to be loaded before obtaining a connection with the database. In JDBC 3.0, a JDBC driver can be loaded either by specifying it in the jdbc.drivers system property, or by using the Class.forName() method. We require invoking the Class.forName() method by loading the Oracle JDBC driver, oracle.jdbc.OracleDriver, using JDBC 3.0.

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

In JDBC 4.0 specifications, the DriverManager class has added support to getConnection() and getDrivers() methods, for the Java SE (Service Provider) mechanism. By using these methods, JDBC drivers may be loaded automatically. The Class.forName() method is not required to be invoked. Loading drivers using the Java SE Service Provider mechanism will be discussed in the Automatic SQL Driver Loading section.

A JDBC connection is represented by a java.sql.Connection object, and may be obtained from a DriverManager by calling the overloaded static getConnection() methods. The getConnection() method is listed in following table:

For example, a connection with the Oracle database may be obtained as shown below:

String url="jdbc:oracle:thin:@localhost:1521:ORCL";
Connection connection = DriverManager.getConnection(url, "oe", "pw");
主站蜘蛛池模板: 英德市| 宜黄县| 鄢陵县| 佛坪县| 宁海县| 揭阳市| 南木林县| 灵丘县| 岳阳市| 息烽县| 石泉县| 富裕县| 扶余县| 石门县| 宣汉县| 江口县| 张家界市| 腾冲县| 建昌县| 盘山县| 乌鲁木齐县| 馆陶县| 清涧县| 庆阳市| 澳门| 鸡泽县| 循化| 定西市| 上思县| 舒城县| 永州市| 梅河口市| 宝山区| 左贡县| 滕州市| 通河县| 元阳县| 万载县| 新巴尔虎右旗| 洪洞县| 竹山县|