Package com.catmiw.testmysql;
Import java.sql. *;
Public class mysqljdbc {public static void main (string args []) {try {class.forname ("org.gjt.mm.mysql.driver); // loads mysql JDBC driver system.out.println (" Success Loading Mysql Driver! ");} Catch (exception e) {system.out.print (" Error Loading MySQL Driver! "); E.PrintStackTrace ();
Try {Connection Connect = DriverManager.getConnection ("JDBC: MySQL: // LocalHost / Catmiw", "root", ""); // Connect URL to JDBC: MySQL // Server Address / Database Name // 2 The parameters are the login username and password system.out.println ("Success Connect MySQL Server!");
Statement Stmt = Connect.createStatement (); ResultSet RS = Stmt.executeQuery ("SELECT * FROT"); while (rs.next ()) {system.out.println (Rs.getstring ("name");
}}} Catch (Exception E) {System.out.print ("Get Data Error!"); E.PrintStackTrace ();}}}
The procedure run is as follows: Success loading mysql driver! Success Connect MySQL Server! A DOG