前段时间写了一个小程序需要使用JDBC,没想到连接出错,查找了一下原因,跟大家分享一下。
如果你使用的MySql版本是8.0以前的,连接的代码如下:
static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/数据库名";
如果你使用的MySql版本是8.0以及8.0以上的版本,连接的代码如下:
static final String JDBC_DRIVER="com.mysql.cj.jdbc.Driver";
static final String DB_URL="jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true";
我希望可以用最简洁的语言,最少的代码量,帮到更多的程序员,希望感觉不错的小伙伴可以给我点一个赞,