【问题标题】:org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet;org.springframework.dao.InvalidDataAccessResourceUsageException:无法提取结果集;
【发布时间】:2017-05-13 11:28:21
【问题描述】:

类实体

@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

我有这个错误

enter image description here

    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

我必须在数据库中手动创建表才能工作:(知道吗?是配置文件有问题吗?谢谢你的帮助:)

【问题讨论】:

    标签: mysql spring-data


    【解决方案1】:

    在您的 application.properties 文件中添加以下属性:

    spring.jpa.hibernate.ddl-auto=update
    

    这将初始化您的数据库。根据 spring 文档查看其他属性:

    https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html

    【讨论】:

    • 我有 getter 和 settter :(
    • 更新了答案。请试试。现在应该会初始化您的数据库。
    • 谢谢,非常感谢您的帮助 :D ,现在可以使用了 :D
    • 您好,在自动创建表格后,我尝试添加另一列,但出现此错误。请问您有什么想法吗?
    • org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class] 中定义名称为“entityManagerFactory”的 bean 创建错误:调用初始化方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    猜你喜欢
    • 2013-06-13
    • 2020-11-04
    • 1970-01-01
    • 2015-02-18
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-17
    相关资源
    最近更新 更多