连接数据库时,URL 里内含乾坤呀
如
db.url = jdbc:mysql://localhost:3306/picture?
解析:
- jdbc:mysql 协议
- localhost IP
- 3306 端口
- picture 数据库名
?后面也能帮我们解决很多常见异常
InvalidConnectionAttributeException: The server time zone value '一堆乱码' is unrecognized
解决办法:在?号后加serverTimezone = GMT
- 数据在数据库中显示乱码(新建数据库时选择支持中文的字符集)
解决办法:在?号后加useUnicode=true&characterEncoding=utf-8
- SSL 异常 (要求SSL连接)
解决办法: 在?号后加useSSL=false
更多,待补充……
另外
高版本的 driverClassName 不再是原来的路径,需要
改成com.mysql.cj.jdbc.Driver。
db.driverClass = com.mysql.jdbc.Driver # 原来的
更换为:( 多了 cj
)
db.driverClass = com.mysql.cj.jdbc.Driver