Basic principles of JDBC

Source: Internet
Author: User

Call Class.forName ("Com.mysql.jdbc.Driver"); Load the MySQL driver into memory, then you will register yourself in DriverManager, the meaning of registration is simply to keep a driver reference in DriverManager, but the specific implementation may be different.

Then the Drivermanager.getconnection method is used to obtain the connection object, which is used in the simple factory method, that is, according to the parameters passed in the specific instance of which driver class.

It could be the driver class for MySQL or the driver class for Oracle, depending on the parameters passed in.

When the connection object is obtained, there is no DriverManager and driver class.

Connection an interface, but it points to a specific connection subclass object.

The database is accessible through the interfaces defined in connection.

So if you want to change the database you're currently using, you just need to change two places,

Class.forName (Specific parameters)

Drivermanager.getconnection (Specific parameters)

So we can configure the two parameters in the configuration file, then we can dynamically change the database used when the program is running, just need to change the configuration file.

Of course, the program must have a third-party jar package for the database.

Basic principles of JDBC

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.