我是SpringMVC和Hibernate的新手。当我运行prgm时,出现SQLGrammarException和表不存在的错误。但是表在数据库中。
我的控制器
@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;
}}
道
@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
。