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