//mysql-connector-java-5.1.3-rc-bin.jar.zip
http://www.java2s.com/Code/JarDownload/mysql-connector-java-5.1.3-rc-bin.jar.zip
public void ConnectToMySql () {
//Connection Information
String host = “127.0.0.1”;
String dbname = “mysql”;
String port = “3306”;
String username = “root”;
String password = “”;
Connection conn;
Statement stmt;
ResultSet rs;
//Try using Driver to connect to MySQL
//Required: Copy .JAR Connector File to $jdk/jre/lib/ext
try {
Class.forName(“com.mysql.jdbc.Driver”);
} catch (ClassNotFoundException e) {
System.err.print (“ClassNotFoundException: ” + e.getMessage ());
return;
}
//Try connect with above info
try {
conn = DriverManager.getConnection (“jdbc:mysql://” +
host + “:” + port + “/” + dbname , username, password);
stmt = conn.createStatement ();
rs = stmt.executeQuery (“select User from user”);
while (rs.next ()) {
String s = rs.getString (“User”);
System.out.println (s);
}
rs.close ();
stmt.close ();
conn.close ();
} catch (Exception ex) {
System.err.println(“SQLException: ” + ex.getMessage());
}
}