数据库连接配置文件基本模板为
#mysql数据源配置
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.60:3306/test
jdbc.username=root
jdbc.password=root
其中test是你要连接的数据库名。
一般来说我们都会在jdbc.url加上useUnicode=true&characterEncoding=UTF-8,用以指定指定字符的编码、解码格式。
还要设置时区serverTimezone=GMT%2B8 //北京时间==东八区时间!=北京当地时间
然后配置文件db.properties就变成了如下形式
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=123456
但是这样写适用于5.0版本的MySQL数据库
如果数据库版本是8.0版本,则需要将jdbc.driver修改为com.mysql.cj.jdbc.Driver,加上了cj,变成了下面这样
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=123456