Jdbc-drivermanager Details

Source: Internet
Author: User

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

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.