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>

至此才真正書寫正確!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM