Some problems and solutions of using JDBC to connect MySQL

Source: Internet
Author: User

The basic format for connecting to a database is as follows:

String url= "Jdbc:mysql://127.0.0.1:3306/imooc?useunicode=true&characterencoding=utf-8";         String user= "root";         String password= "Tiger";         1. Load the driver         class.forname ("Com.mysql.jdbc.Driver");         2. Get the database link         Connection conn=drivermanager.getconnection (URL, USER, PASSWORD);         3. Through database connection operation database, to realize adding and deleting (using Statement Class)         Statement st=conn.createstatement ();         ResultSet rs=st.executequery ("SELECT * from user");         4. Processing the returned results of the database (using the ResultSet Class) while         (Rs.next ()) {            System.out.println (rs.getstring ("user_name") + ""                          +rs.getstring ("User_password"));         }                Close Resource         rs.close ();         St.close ();         Conn.close ();

Problem 1:no suitable driver found for JDBC

Reason: URL is wrong, MySQL write a ":"

Hara Url:jdbc:mysql//127.0.0.1:3306/xxx

Modified URL:jdbc:mysql://127.0.0.1:3306/xxx

Issue 2:access denied for user ' root ' @ ' localhost ' (using Password:yes)

Reason: The port of the URL is wrong, I want to connect to the local 3307, the wrong write 3306. Oh.

Issue 3:mysql warning warn:establishing SSL connection without server ' s identity verification is not recommended

This is a warning is not an error, and later use is not affected. This means that an SSL connection is established, but the server does not have authentication, which is not recommended.

It does not affect your access to the database.

If you do not want to see this line of hints, the solution is to add jdbc:mysql://127.0.0.1:3306/xxx after your URL? useunicode=true&characterencoding=utf-8 &usessl=false

Some problems and solutions of using JDBC to connect MySQL

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.