与区别

时间:2025-03-18 07:05:45

与区别

是mysql-connector-java 5及 5 以下的

配置方式:

driverClassName=
url=jdbc:mysql://localhost/dbName?useUnicode=true&characterEncoding=utf8
username=root
password=root

是mysql-connector-java 6及 6以上的

JDBC连接Mysql6 时,需要指定时区serverTimezone:

serverTimezone

设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong

driverClassName=
url=jdbc:mysql://localhost/dbName?serverTimezone=UTC&?useUnicode=true&characterEncoding=utf8
username=root
password=root

常见异常:

1.若使用的jar包是mybatis-connection-Java 6 及以上的,却使用了就会包如下异常:
Loading class ''. This is deprecated. The new driver class is''. 

产生原因:MySql版本问题

解决方法:把 改为

-connection-Java 6 及以上的url还需要配置时区serverTimeZone,否则会报如下异常:
The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. 

产生原因:mybatis-connection-Java 6 及以上的url未配置时区

解决方法:在url上加上时区