Java MySQL8.0连接

MySQL8.0以下连接语句

Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名称","数据库连接名","数据库连接密码");

MySQL8.0及其以上连接语句

Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8","数据库连接名称","数据库连接密码");
jdbc.driver=com.mysql.cj.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/数据库名称?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
注:GMT%2B8是解决时差问题,北京时间与格林威治时间相差8个小时

jdbc.username=数据库连接名称

jdbc.password=数据库连接密码

你可能感兴趣的:(Java)