请求处理失败;嵌套异常是org.hibernate.exception.SQLGrammarException:无法插入:

时间:2015-02-04 06:54:05

标签: java hibernate spring-mvc

我是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;
}}

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。

1 个答案:

答案 0 :(得分:0)

信息很清楚:

Table 'test.exam' doesn't exist

您必须创建表格exam