1, first download the MySQL installation package, download the link mysql download, and then install.
2. Enter the user name and password at the time of installation to connect to the database.
3. Install the MYSQ JDBCL driver in Eclipse, the installation steps are as follows:
To test if the MQL is successfully connected, code:
Package Day_09;import java.sql.*;p ublic class test{public static void Main (string[] args) {String url= "Jdbc:mysql://loca Lhost:3306/mydb "; String user= "root"; String password= "281889"; Connection Conn=null; Statement Stmt=null; ResultSet Rs=null; try {class.forname ("com.mysql.jdbc.Driver"); Conn=drivermanager.getconnection (Url,user,password); Stmt=conn.createstatement (); String SQL; Sql= "INSERT into student values (2014218, ' Li Yue ', ' female ')"; Stmt.execute (SQL); Sql= "SELECT * from student"; rs = stmt.executequery (SQL); System.out.println ("School Number" + "\t\t\t" + "name" + "\t\t\t" + "gender"); String name = NULL; while (Rs.next ()) {name = Rs.getstring ("sname"); System.out.println (rs.getstring ("sno") + "\t\t\t" + name+ "\t\t\t" +rs.getstring ("Sex")); }} catch (ClassNotFoundException E1) {System.out.println ("Database driver does not exist!") "+e1.tostring ()); } catch (SQLException E2) {System.out.println ("the database has an exception" +e2.tostring ()); } finally {try {if (rs!=null) Rs. Close (); if (stmt!=null) stmt.close (); if (conn!=null) conn.close (); } catch (SQLException e) {System.out.println (e.tostring ()); } } } }
Printing results:
Java Connection MySQL Database