JDBC Series Tutorial (2) --- Drive Settings

zhaozj2021-02-16  78

DriverManager This overview is taken from "JDBCTM Database Access from Javatm: a Tutorial and Annotated Reference", which is currently being written by JavaSoft. This book is both a JDBC tutorial and an authority reference manual that will be published by the Addison-Wesley Publishing Company in the spring of the Java series in the 1997 Spring. 3.1 Overview The DRIVERMANAGER class is the management of JDBC, which acts between users and drivers. It tracks the available drivers and establishes a connection between the database and the corresponding driver. In addition, the DRIVERMANAGER class also handles transactions such as the display of the driver login time limit and login and tracking messages. For simple applications, the unique way to use directly in this class is DriverManager.getConnection. As indicated by the name, the method will establish a connection to the database. JDBC allows users to call DriverManager's methods with GetDriver, GetDrivers, and RegisterDriver and Driver. Connect. But in most cases, let DRIVERMANAGER class management establish the details of the connection. 3.1.1 Tracking Available Drivers The DriverManager class contains a column DRIVER class that has been registered by calling method DriverManager.RegisterDriver. All DRIVER classes must contain a static part. It creates an instance of this class and then register when the DriverManager class is loaded. In this way, DriverManager.RegisterDriver will not directly call DRIVERMANAGER.REGISTERDRIVER directly; it is automatically called by the driver when the driver is loaded. Load the Driver class and then automatically register in the DriverManager: By calling methods Class.Forname. This will explicitly load the driver class. Since this is not related to external settings, it is recommended to use this method of loading the driver. The following code load class acme.db.driver: class.forname ("acme.db.driver"); if you write acme.db.driver as loaded as loaded, Create an instance, and call DriverManager.RegisterDriver as parameters (this This is, then it is in the DriverManager's driver list and can be used to create a connection. Add the driver to the Java.lang.System's properties JDBC.DRIVERS. This is a list of driver class names loaded by the DriverManager class, separated by colon: When the DriverManager class is initialized, it searches for system properties JDBC.DRIVERS, if the user has entered one or more drivers, the DriverManager class will attempt to load they. The following code shows how the programmer enters three driver classes in ~ / .hotjava / Properties (when startup, Hotjava will load it into the system properties list): jdbc.drivers = foo.bah.driver: wombat.sql. Driver: Bad.Test.ourcesDriver; the first call to the DriverManager method will automatically load these driver classes. Note: The second method of loading the driver requires a long-lasting preset environment. If you can't guarantee this, the call method class.Forname Explicitly loading each driver is more secure.

转载请注明原文地址:https://www.9cbs.com/read-14383.html

New Post(0)