java连接mySQL
下载mysql-connector-java-8.0.22.jar
略
连接过程:
- 导入必要的包:
import java.sql.*;
import java.util.Properties;
- 驱动创建:
Driver driver = new com.mysql.cj.jdbc.Driver();
- 连接信息:
String url = "jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai";
Properties userInfo = new Properties();
userInfo.setProperty("user", "root");
userInfo.setProperty("password", "");
- 连接:
Connection conn = driver.connect(url, info);
System.out.println(conn);
- 结果:
连接成功了。