Create a new folder in your project before you write the code, then copy the Java and MySQL drives into it and add it to build path, OK.
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import Java.sql.ResultSet;
Import java.sql.Statement;
public class JBD {
private static final String URL = "JDBC:MYSQL://127.0.0.1:3306/IMOOC";
private static final String USER = "root";
private static final String PASSWORD = "OpenLab";
/**
* @param args
*/
public static void Main (string[] args) throws exception{
TODO auto-generated Method Stub
To load the database drive first
Class.forName ("Com.mysql.jdbc.Driver");
Get a database connection
Connection conn = drivermanager.getconnection (URL, USER, PASSWORD);
Operation database, to implement additions and deletions to search
Statement stmt = Conn.createstatement ();
ResultSet rs = stmt.executequery ("SELECT * from users");
while (Rs.next ())
{
System.out.println (rs.getstring ("sno") + rs.getshort ("sname"));
}
}
}
Open the database before you do that. The Run Code console then displays the SQL statement that is queried by the premises.
Java connection MySQL Database specific steps