In order to connect MySQL serve, you just need to invoke MySQL API as the following code:
protected boolean connectMySQL() {
//Register the JDBC driver for MySQL.
try {
Class.forName("com.mysql.jdbc.Driver");
//Define URL of database server for
// database named xam the localhost
// with the default port number 3306.
String url = "jdbc:mysql://localhost:3306/xam";
//Get a connection to the database for a
// user named auser with the password
// drowssap, which is password spelled
// backwards.
Connection con = null;
con = DriverManager.getConnection(url, "root", "");
//Display URL and connection information
System.out.println("URL: " + url);
System.out.println("Connection: " + con);
//Get a Statement object
stmt = con.createStatement();
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return true;
}