gpt4 book ai didi

java - 嵌套异常是 org.hibernate.exception.SQLGrammarException : could not extract ResultSet Hibernate+SpringMVC

转载 作者:行者123 更新时间:2023-12-02 03:41:43 25 4
gpt4 key购买 nike

我正在尝试从数据库中获取记录,但出现上述错误

这是我的类(class),具有适当的 getter 和 setter

public class User {
private int id;
private String username;
private String password;
private String email;

我还创建了数据库并使用以下配置将数据插入其中

<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/usersdb"/>
<property name="username" value="root"/>
<property name="password" value=""/>
</bean>

这是完整的堆栈跟踪

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/spring] threw exception [Request processing failed; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'usersdb.users' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)

请问我刚接触 Spring MVC 和 Hibernate 可能出了什么问题

User.java的完整代码

package net.codejava.spring.model;

public class User {
private int id;
private String username;
private String password;
private String email;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}

最佳答案

你错过了一些东西

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;


import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name="User")

public class User implements Serializable{

关于java - 嵌套异常是 org.hibernate.exception.SQLGrammarException : could not extract ResultSet Hibernate+SpringMVC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36768244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com