PackageSQL;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement; Public classJdbctest { Public StaticString driver= "Com.mysql.jdbc.Driver"; Public StaticString url= "Jdbc:mysql://127.0.0.1:3306/test"; Public StaticString user= "Root"; Public StaticString password= "333"; Public Static voidMain (string[] args) {Connection con; Statement Statement; ResultSet rs; Try { //Load DriverClass.forName (Driver); //connecting to a databasecon=drivermanager.getconnection (URL, user, password); if(!con.isclosed ()) System.out.println ("Connect successed"); Statement=con.createstatement (); String SQL= "SELECT * FROM TMP"; RS=statement.executequery (SQL); while(Rs.next ()) {String RQ=rs.getstring ("RQ"); System.out.println ("Rq=" +RQ); } rs.close (); Con.close (); } Catch(ClassNotFoundException e) {System.out.println ("Drive failed to load"); E.printstacktrace (); }Catch(SQLException e) {System.out.println ("SQL execution failed"); E.printstacktrace (); }Catch(Exception e) {}finally{ } }}
Java MySQL Pure drive connection