注意:在连接之前导入jar包
链接:https://pan.baidu.com/s/1wtqUKb0IuY3RcwJOUlNmUg mysql8.0能用的连接jar包
提取码:edt5
public class DBUtils {
private static String url = "jdbc:mysql://localhost:3306/yd-webshop?useSSL=false&serverTimezone = GMT";
private static String password="123456";
private static String user="root";
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
//1.数据库驱动加载
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();//mysql8.0后用的加载方式
//Class.forName("com.mysql.jdbc.Driver").newInstance(); mysql8.0之前的加载方式
//2.创建数据库连接
Connection connection= DriverManager.getConnection(url,user,password);
System.out.println("测试方法"+connection);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}