gpt4 book ai didi

java - 请求处理失败;嵌套异常是 org.hibernate.exception.SQLGrammarException : could not insert:

转载 作者:太空宇宙 更新时间:2023-11-04 14:11:03 24 4
gpt4 key购买 nike

我是 SpringMVC 和 Hibernate 的新手。当我运行 prgm 时,我收到错误 SQLGrammarException 并且表不存在。但数据库中有表。

我的 Controller

@Controller
public class ExamController {
@Autowired
private ExamDAO daoObj;
@RequestMapping(value="/submitForm.do",method=RequestMethod.POST)
public ModelAndView SubmitForm(@RequestParam("studCon")int Contact,
@RequestParam("studName")String Name, @RequestParam("studpwd") String password)
{

ExamModel modObj = new ExamModel();

modObj.setStudCon(Contact);
modObj.setStudName(Name);
modObj.setStudpwd(password);

daoObj.save(modObj);
ModelAndView mvcObj=new ModelAndView("Result");
return mvcObj;
}}

DAO

  @Repository 
@Transactional
public class ExamDAO {
@Autowired
private SessionFactory sessFac;

@SuppressWarnings("unchecked")
public List<String[]> getAllItem()
{
Criteria c =sessFac.getCurrentSession().createCriteria(ExamModel.class);
);
return c.list();
}
public int save(ExamModel ge)
{

return (Integer) sessFac.getCurrentSession().save(ge);
}}

型号

  @Entity
@Table(name = "exam")

public class ExamModel implements Serializable {
private static final long serialVersionUID = -723583058586873479L;
@Id
@Column(name="stud_id")
@GeneratedValue(strategy=GenerationType.AUTO)
private int studId;

@Column(name="stud_name")
private String studName;

@Column(name="phone")
private int studCon;

@Column(name="pwd")
private String studpwd;

public int getStudId() {
return studId;
}

public void setStudId(int studId) {
this.studId = studId;
}

public String getStudName() {
return studName;
}

public void setStudName(String studName) {
this.studName = studName;
}

public int getStudCon() {
return studCon;
}

public void setStudCon(int studCon) {
this.studCon = studCon;
}

public String getStudpwd() {
return studpwd;
}

public void setStudpwd(String studpwd) {
this.studpwd = studpwd;
}
}

你能帮我摆脱这个错误吗?该错误表明无法插入,因为存在 SQLException。

最佳答案

信息非常明确:

Table 'test.exam' doesn't exist

您必须创建表exam

关于java - 请求处理失败;嵌套异常是 org.hibernate.exception.SQLGrammarException : could not insert:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315224/

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