MySQL JDBC connection test program

xiaoxiao2021-03-06  65

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

转载请注明原文地址:https://www.9cbs.com/read-112184.html

New Post(0)