Import Mysql--conncetor--java--jars in eclipse
Method One: Right-click on the project item, point build path->configure build Path-->libraries-->add External JARs (add local JARs package)-->apply
Import java.sql.*;p Ublic class Mysqljdbc {public static void main (String args[]) {try {class.forname ("com.mysq L.jdbc.driver "); Load MySQL JDBC driver//class.forname ("Org.gjt.mm.mysql.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:3306/test", "root", "123" ); The connection URL is jdbc:mysql//server address/database name, the following 2 parameters are login username and password System.out.println ("Success connect MySQL server!"); Statement stmt = Connect.createstatement (); ResultSet rs = stmt.executequery ("SELECT * from user"); User is the name of your table while (Rs.next ()) {System.out.println (rs.getstring ("name")); }} catch (Exception e) {System.out.print ("Get Data error!"); E.printstacktrace (); } }}
Eclipse Import jar Package connection MySQL