Use MySQL JDBC Connector

Download JDBC connector. Include the library in the class-path.

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, user, password);

Statement s = conn.createStatement();
String sql = "SELECT * FROM person";
s.execute(sql);
ResultSet rs = s.getResultSet();
while(rs.next()){
	System.out.println(rs.getString("name") + "\t" + rs.getInt("age") + "\t" + rs.getString("sex") + "\t" + rs.getString("location"));
}
rs.close();
s.close();
Advertisements