Matching environment
Step 1: Download the package: Link: https://pan.baidu.com/s/1puGWFgZJde3KapUQiOgqsA Extraction code: 6v9d After copying this content, open the Baidu Netdisk mobile app, the operation is more convenient.
Step 2: Reference the package
package mysql_1;
import java.sql.*;
public class mysql_01 {
public static void main(String[] args) {
// TODO 自动生成的方法存根
try {
Class.forName("com.mysql.cj.jdbc.Driver");//每个人的不是从我这里下载的jar包可能不同,可能为com.mysql.jdbc.Driver
//这个是在mysql默认的是3306端口和有一个自己创建的名字为Java的数据库
String URL = "jdbc:mysql://localhost:3306/java?serverTimezone=UTC&characterEncoding=utf-8"; // 连接MySQL数据库的路径
String USERNAME = "root"; // 连接MySQL数据库的用户名
String PASSWORD = "root"; // 连接MySQL数据库的密码
Connection con = DriverManager.getConnection(URL, USERNAME, PASSWORD); // 初始化连接MySQL数据库的对象1
System.out.print(con);
con.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
The next blog is specifically about the use of databases