Spring boot and mysql 初體驗

基于http://www.itdecent.cn/p/b6932740f3c0來學習 Spring Boot開發(fā),出現(xiàn)的問題記錄如下:


1. 編譯錯誤

Error:(32, 24) java: 不兼容的類型: java.lang.Long無法轉換為com.yuqiyu.lessonthree.entity.UserEntity

userJPA.delete(id); 報錯,

修改為?

// userJPA.delete(id);

userJPA.deleteById(id);

2.? ?將application.yml的配置文件修改?application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.show-sql=true

spring.jpa.database=mysql


3.??Loading class `com.mysql.jdbc.Driver'. This is deprecated.

修改application.properties 中的 datasource.driver-class

#spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver


4.? ?超時:

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

解決:

#spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=false

spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&serverTimezone=UTC&autoReconnect=true

參考:https://www.cnblogs.com/chrischennx/p/7279215.html


5.? 輸入?http://localhost:8080/user/list, 無反饋。

java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

原因:Caused by: com.mysql.cj.exceptions.CJException: Unknown database

解決辦法: 新建 test的 數(shù)據(jù)庫文件,和對應的表格t_user


6: 執(zhí)行?http://localhost:8080/user/save?name=admin&age=22&address=jinan,?, 無反饋。

原因:

Hibernate: select next_val as id_val from hibernate_sequence for update

2019-08-29 15:16:20.993 ERROR 5284 --- [nio-8080-exec-6] o.hibernate.id.enhanced.TableStructure? : could not read a hi value

java.sql.SQLSyntaxErrorException: Table 'test.hibernate_sequence' doesn't exist

解決:

//@GeneratedValue

@GeneratedValue(strategy = GenerationType.IDENTITY)

參考:

https://www.cnblogs.com/app3306/p/9176575.html

7.?執(zhí)行?http://localhost:8080/user/save?name=admin&age=22&address=jinan,?, 無反饋。

錯誤:? java.sql.SQLException: Field 't_id' doesn't have a default value

解決:在mysql數(shù)據(jù)庫中,如果自增長id沒有設為Auto Increment,在java程序中就會報java.sql.SQLException: Field 'id' doesn't have a default value錯誤。


參考:

https://blog.csdn.net/xinghuo0007/article/details/51810867

http://www.programmersought.com/article/7674510934/

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容