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