import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
private static final String URL="jdbc:mysql://127.0.0.1:3306/student";
private static final String USER="root";
private static final String PASSWORD="root";
public static void main(String[] args) throws ClassNotFoundException, SQLException {
//1、加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//2、获得数据库的连接
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
//3、通过数据的连接来操作数据库,实现增删改查
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("select name,age from stu");
while(rst.next()){
System.out.println(rst.getString("name")+","+rst.getInt("age"));
}
}
}