MYSQL Database management Tools
JAVA programming language
Database driver (Java and MySQL docking mode)
To the official web download driver load driver
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.Statement;
public class sql{
public static void Main (string[] args) {
try{
Load drivers loaded into the JVM
Class.forName ("Com.mysql.jdbc.Driver");
Getconnection () method, linking to the MySQL database
Connection con = drivermanager.getconnection ("jdbc:mysql://localhost:3306/Library name", "username", "password");
Verify that the link is successful
if (!con.isclosed ())
SYSTEM.OUT.PRINTLN ("Succeeded connecting to the Databases");
Create a statement object to execute the SQL statement
Statement sta = con.createstatement ();
The SQL statement to execute
String sql = "SELECT * from student";
ResultSet class holds the obtained result set
ResultSet rs = sta.executequery (SQL);
while (Rs.next ()) {
String name = rs.getstring ("sname");
int id = rs.getint ("id");
System.out.println (name+ "\ t" +id);
}
}catch (Exception e) {
E.printstacktrace ();
}
}
}
MySQL and Java (class notes)