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

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");
主站蜘蛛池模板: 年辖:市辖区| 克什克腾旗| 曲周县| 鸡西市| 托里县| 四子王旗| 屯昌县| 苏州市| 淮南市| 平泉县| 府谷县| 屏东县| 寻乌县| 漳平市| 怀安县| 陵川县| 宣汉县| 浦江县| 招远市| 仲巴县| 黔东| 彰化县| 和林格尔县| 杭州市| 万全县| 兴文县| 北辰区| 交口县| 盐源县| 伊吾县| 丰城市| 新和县| 轮台县| 卓资县| 桂阳县| 双流县| 比如县| 兰州市| 肥乡县| 格尔木市| 道真|