Driver settings for basic JDBC tutorials on Java database interfaces

Source: Internet
Author: User
The DriverManager class is the management layer of JDBC and acts between users and drivers. It tracks available drivers and establishes connections between the database and the corresponding drivers. In addition, the DriverManager class also processes transactions such as the driver logon time limit and the display of logon and tracing messages.
For simple applications, the only method that programmers need to directly use in this class is DriverManager. getConnection. As shown in the name, this method establishes a connection with the database. JDBC allows users to call Dr
Send a free monthly message with UC via Sina Diantong
Why did Americans hit the wrong target? Caiso watch 5.8 off
IverManager methods include getDriver, getDrivers, registerDriver, and Driver methods. However, in most cases, it is best to set up the connection details for DriverManager class management.
1. Track available drivers
The DriverManager class contains a column of Driver classes that have been registered by calling the DriverManager. registerDriver method. All Driver classes must contain a static part. It creates an instance of this class and registers the DriverManager class when the instance is loaded. In this way, the user will not directly call DriverManager. registerDriver, but will be automatically called by the driver when loading the driver. There are two ways to load the Driver class and then automatically register in DriverManager:
Call Class. forName. This will explicitly load the driver class. Because this is irrelevant to external settings, we recommend that you use this method to load the driver. Run the following code to load acme. db. Driver:
Class. forName ("acme. db. Driver ");
If you set acme. db. the Driver program creates an instance when it is loaded and calls the DriverManager with the instance as the parameter. registerDriver (this should have been the case) is included in the driver list of DriverManager and can be used to create a connection.
Add the driver to the jdbc. drivers attribute of java. lang. System. This is a list of driver class names loaded by the DriverManager class, separated by a colon: it searches for system properties jdbc when initializing the DriverManager class. drivers. If you have entered one or more drivers, the DriverManager class will try to load them. The following code describes how programmers can ~ /. Enter three driver classes in hotjava/properties (at startup, HotJava loads them to the system property list ):
Jdbc. drivers = foo. bah. Driver: wombat. SQL. Driver: bad. test. ourDriver;
The first call to the DriverManager method will automatically load these driver classes.
Note: The second method for loading the driver requires a persistent preset environment. If this is not guaranteed, it is safer to call the Class. forName method to explicitly load each driver. This is also the method for introducing specific drivers, because once the DriverManager class is initialized, it will no longer check the jdbc. drivers attribute list.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.