The most standard Java MySQL connection and javamysql connection
Package com. runoob. test; import java. SQL. *; public class MySQLDemo {// JDBC driver name and Database URL static final String JDBC_DRIVER = "com. mysql. jdbc. driver "; static final String DB_URL =" jdbc: mysql: // localhost: 3306/RUNOOB "; // username and password of the database, you need to set static final String USER = "root"; static final String PASS = "123456"; public static void main (String [] args) {Connection conn = null; statement stmt = null; tr Y {// register the JDBC Driver Class. forName ("com. mysql. jdbc. driver "); // open the link System. out. println ("connect to the database... "); conn = DriverManager. getConnection (DB_URL, USER, PASS); // execute the query System. out. println ("instantiate the Statement pair... "); stmt = conn. createStatement (); String SQL; SQL = "SELECT id, name, url FROM websites"; ResultSet rs = stmt.exe cuteQuery (SQL); // expand the result set database while (rs. next () {// retrieves int id = rs through a field. getInt ("id"); String n Ame = rs. getString ("name"); String url = rs. getString ("url"); // output data System. out. print ("ID:" + id); System. out. print (", site name:" + name); System. out. print (", site URL:" + url); System. out. print ("\ n");} // close rs after completion. close (); stmt. close (); conn. close ();} catch (SQLException se) {// process the JDBC error se. printStackTrace ();} catch (Exception e) {// process Class. forName error e. printStackTrace ();} finally {// close the resource try {If (stmt! = Null) stmt. close ();} catch (SQLException se2) {}// do nothing try {if (conn! = Null) conn. close () ;}catch (SQLException se) {se. printStackTrace () ;}} System. out. println ("Goodbye! ");}}