generatorConfig-mysql.xml中连接数据库的正确书写方式。

在做spring boot开发时,刚开始实训的时候一直做的数据库表的增删改查,但是在MybatisGenerator自动生成java文件时,在XML文件中由于书写不正确一直连接不上数据库。

刚上手项目,错误写法是这样的:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://localhost:3306/renping"   

userId="root"

password="7829*****">

</jdbcConnection>

 

可以看到的确有renping这个数据库存在,但是为什么一直报错:unknown database “renping”

之后我又上网找,说是写成如下的样子:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://localhost:3306/day1?characterEncoding=utf-8"

userId="root"

password="7829*****">

</jdbcConnection>

结果还是以前的错误。

又改成如下:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://localhost:3306renping?useUnicode=true&characterEncoding=utf-8&useSSL=false"

userId="root"

password="7829*****">

</jdbcConnection>

错误又变成了这个:

The reference to entity "useSSL" must end with the ';' delimiter.

原来是没有使用转义字符,参考博文之后得到了答案:

https://blog.csdn.net/qq_33530388/article/details/70352720

这次终于修改成功,并且终于知道了我应该写表的名字,而不是自己数据库的名字修改如下:

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

  connectionURL="jdbc:mysql://localhost:3306/day1?useUnicode=true&characterEncoding=utf-8&useSSL=false"

userId="root"

password="7829*****">

</jdbcConnection>

至此才真正书写正确!

猜你喜欢

转载自www.cnblogs.com/RPlandscape/p/10141738.html