//需要在java工程加载 java连接的 API
import java.sql.*;
public class MysqlJabc {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}
catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
try{
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test","root","123");
System.out.println("Success connect Mysql server!");
Statement stmt =connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from user");
while(rs.next()){
System.out.println(rs.getString("name"));
}
}
catch(Exception e){
System.out.println("get data error!");
e.printStackTrace();
}
}
}