在做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>
至此才真正書寫正確!
