类实体
@Entity
@Table
public class Camera {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String place;
private String address;
public Long getId() {
return id;
}
public String getName() {
return name;
}
public String getPlace() {
return place;
}
public void setId(Long id) {
this.id = id;
}
//Constructors, getters and setters are not shown here
}
application.properties配置文件
spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=
server.port=9000
我有这个错误
Exception in thread "Thread-3" org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: La table 'springbootdb.camera' n'existe pas
我必须手动创建数据库中的表才能工作:(任何想法?配置文件中是否存在问题?感谢您的帮助:)
答案 0 :(得分:0)
在application.properties
文件中添加以下属性:
spring.jpa.hibernate.ddl-auto=update
这将初始化您的数据库。根据春季文档,看看其他属性:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html