参考:添加链接描述
我本来是在Mybatis全局配置中,写死数据库连接参数的
版本为8.0.18 在java和xml中,&
都要使用&
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/demombs?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
运行代码一切正常
我现在想用配置文件来防止数据库连接参数 就把上面的东西copy放到了db.properties,如下:
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/demombs?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Hongkong
jdbc.username=root
jdbc.password=123456
然后报错,截取部分:
### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useSSL=false&serverTimezone=Hongkong'.
### The error may exist in mapper/Usermap.xml
### The error may involve test.getUser
### The error occurred while executing a query
### Cause: java.sql.SQLNonTransientConnectionException: Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';useSSL=false&serverTimezone=Hongkong'.
再三确认我copy得没问题,又改时区又删参数的,都有问题。百度半天也没到点子上,最后看到了参考博客,因为部分符号无法编译
解决:将&; 换成&
成功