- 下载MySQL驱动
驱动下载地址:https://downloads.mysql.com/archives/c-j/
选择 jar包下载
MySQL连接
//注册驱动
Class.forName("com.mysql.jdbc.Driver");
//建立连接
String url = "jdbc:mysql://localhost:3306/employees";
String user = "root";
String pswd = "123456";
Connection connection = DriverManager.getConnection(url,user,pswd);
//定义查询sql语句
String sql = "select * from tb_student";
//执行查询sql语句
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
//关闭资源
statement.close();
connection.close();
System.out.println("连接关闭!");
- url 连接路径