Java MySQL8.0连接

版权声明:最终解释权归属Hern、HernSong(hernsong)、苍鹭、www.hernsong.com所有! https://blog.csdn.net/qq_36761831/article/details/87537211

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=数据库连接密码

猜你喜欢

转载自blog.csdn.net/qq_36761831/article/details/87537211