Java link MySQL database operationJava link mysql first loads MySQL jdbc driver in Java
Class.forName ("Com.mysql.jdbc.Driver");
Second, establish a connection with MySQL existing database
String url = "Jdbc:mysql://localhost:3306/mydata?userunicode=true&characterencoding=utf-8&usessl=false"
Where JDBC is called the JDBC driver, MySQL refers to the database type here is the MySQL database, localhost refers to the link address, here refers to the local MySQL database, 3306 is the port number used by MySQL,useunicode=true& Characterencoding=utf-8 is the encoding format that is used when displaying database data, Usessl=false the SSL link is off, the SSL connection must be established in the higher version, or an error will be made.
Strinf user = "root"; String psaawd = "123456"
User is the MySQL username, passwd is the password
Connection con = drivermanager.getconnection (URL,USER,PASSWD);
As part of the initialization, the DriverManager class attempts to load the driver class that is referenced in the "Jdbc.drivers" system property
getconnection (string url, string user, String password) method attempts to establish a connection to a given database URL
Since then, a link has been established with the database
public static Connection getconnection () throws sqlexception,java.lang.classnotfoundexception{// Load the MySQL JDBC driver class.forname ("Com.mysql.jdbc.Driver");//Get the URL and user name and password of the connection string url = "jdbc:mysql://localhost:3306/ Mydate?useunicode=true&characterencoding=utf-8&usessl=false "; String user = "root"; String passwd = "123456";//Create an instance connection to the database connection con = drivermanager.getconnection (URL, user,passwd); return con;}
Java Link MySQL operation