1> Registration-driven issue.
Drivermanager.registdriver (New Driver ()); ==> This kind of registration method, do not use in the future development.
Use the following methods:
Class.forName ("Com.mysql.jdbc.Driver");
2> Why?
In the code of the driver class, we can see that there is a static block of code. The static code block has already done the registration-driven thing. So we just need to load
The Registdriver method is the equivalent of calling the driver class.
3> What are the benefits of using Class.forName?
* If the Registdriver method is called, it is equivalent to creating two driver objects, wasting resources.
* Use the Forname method. Because the name of the driver class is filled in as a string, we put the name in the configuration file each time it is read from the configuration file.
Then switching the driver class is very convenient. It also means that switching the database is convenient.
--------------------------------------------------------------------------------------------------------------- -------
4. Get the details of connection
Drivermanager.getconnection ("url", "username", "password");
URL fill in the format:
Outer protocol: Internal protocol://Host name [IP Address]: Port number/library name? parameter key 1 = parameter value & parameter key 2 = parameter value
Jdbc:mysql://localhost:3306/day15?useunicode=true&characterencoding=utf-8
Or
If you point to this machine and the default port number is not modified, you can omit it directly. As follows:
Jdbc:mysql:///day15?useunicode=true&characterencoding=utf-8
Combined with the above-mentioned convenience to switch databases.
When we write, we can also write the above 3 parameters to the configuration file.
Jdbc-drivermanager Details