Spring boot and mysql 初体验

基于https://www.jianshu.com/p/b6932740f3c0来学习 Spring Boot开发,出现的问题记录如下:


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的 数据库文件,和对应的表格t_user


6: 执行 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. 执行 http://localhost:8080/user/save?name=admin&age=22&address=jinan, , 无反馈。

错误:  java.sql.SQLException: Field 't_id' doesn't have a default value

解决:在mysql数据库中,如果自增长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/

你可能感兴趣的:(Spring boot and mysql 初体验)