DriverManager class
This class is used to load the driver, all of its members are static members, so there is no need to instantiate it in the program and access it directly through the class name.
The DriverManager class is a JDBC management layer that acts to load drivers between users and drivers
Class.forName ("Company name. Database name. Driver name")
such as: Class.forName ("Sun.jdbc.odbc.jdbcOdbcDriver")
Establish a connection
After loading the driver class and registering with the DriverManager class, you can use it to establish a connection to the database. When the call to Driver.Manager.getConnection () makes a connection request, DriverManager checks each driver to see if it can establish a connection.
Method: Connection getconnection (String url,string user,string password)
Where user and password are users and passwords that log on to the database
The first parameter is the URL that points to the database, which is formatted as follows:
JDBC: (subprotocol):(subname)
Subprotocol: A child protocol that specifies which database to connect to or how to connect to the database
SubName: Establish a connection that can be a data source name or point to an online database
For example: The following are examples of commonly used drivers (JDBC-ODBC bridge drivers) and a student data source with anonymous logins:
Class.forName ("Sun.jdbc.odbc.jdbcOdbcDriver");//Load Driver
String url= "Jdbc:odbc:student";
Connection cn=drivermanager.getconnection (URL, "anonymous", "");
Getconnection (): Returns a Connection class object. If successful, this object points to a connection to this database; otherwise, this object will be null NULL
Connection class
The connection class is a connection that points to the same database.
Role: Manage connections to the database, such as: queries that send queries to the database and query results from the receiving database are based on it, and the connection is closed after all tasks that have connected to the database have been completed.
Method:
Statement createstatment (): Creates a new Statement object that can send query information to the database
void Close (): Closes the connection to the database and frees the occupied JDBC resource
Boolean Isclose (): Determines whether the database is still connected