1.在xml文件中配置URL时注意加入如下字段:
?characterEncoding=utf8& amp;useSSL=false& amp;serverTimezone=UTC& amp;rewriteBatchedStatements=true
<!--连接数据库的url -->
<property name="url"
value="jdbc:mysql://localhost:3306/spring?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true" />
这里的"&"为转义字符,其实就是‘&’
xml文件中有些特殊字符是被禁止的,而‘&’就是其中一个,
如果要想使用它,需要用到它的转义字符"& amp;"
2.在Java文件中时注意:
Class.forName("com.mysql.cj.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/chapter01?serverTimezone=GMT%2B8&useSSL=false";
加载驱动时要写成com.mysql.cj.jdbc.Driver,
URL后面要添加?serverTimezone=GMT%2B8&useSSL=false";