您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Java >> struts2中的action取到了值,但插入不到数据库中,求助

struts2中的action取到了值,但插入不到数据库中,求助

来源:网络整理     时间:2016/7/20 21:59:04     关键词:

关于网友提出的“ struts2中的action取到了值,但插入不到数据库中,求助”问题疑问,本网通过在网上对“ struts2中的action取到了值,但插入不到数据库中,求助”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: struts2中的action取到了值,但插入不到数据库中,求助
描述:

我们用的是ssh2框架搭建的,要做一个物理实验系统。需要在预习题库中插入题目,用的是xheditor编辑器。
action是这个:
public String saveQuestion() throws IOException{
try{
PreviewLibrary question = new PreviewLibrary();
question.setModel(1);//题目类型 integer的 1是多选题(无所谓啦)
question.setTitle(title);//题目内容string
question.setAnswer(answer);//答案也是string
question.setExperiment(experimentService.getExperiment(experimentId));//在数据表中预习题的外键是experiment_id,在实体类中就是experiment啦
if ( previewId== null || previewId <= 0) {
this.pagePrint(previewLibraryService.savePreviewLibrary(question));//因为写了个baseDao,这个最终调用的就是session里面的savaorupdate方法啦,另外pagePrint这个函数有一个返回值,供前台的ajax回调用的,“1”就是成功
} else {
}
}catch(Exception e){
this.pagePrint("0");//我们的程序现在就是进这里面去了 struts2中的action取到了值,但插入不到数据库中,求助我已经debug了一天了,好难过,求大神帮帮我
e.printStackTrace();
throw new RuntimeException();
}
return NONE;
}
实体类Previewlibrary
public class PreviewLibrary implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/** 预习题id */
private Long previewId;
/** 所属实验  */
private Experiment experiment;
/** 预习题型:0=单选,1=多选,2=判断 */
private Integer model;
/** 题目 */
private String title;
/** 答案:单选、多选————由选项拼接成字符串(eg:“A,B,C,D”)
判断————0=对、1=错 */
private String answer;
//下面三个就不是必须的了
/** 出题人id */
private Long peopleId;
/** 创建时间 */
private Timestamp createTime;
/** 修改时间 */
private Timestamp modifyTime;
//这个是previewlibraryDaoImp里面有关的方法
public void savePreviewLibrary(PreviewLibrary previewLibrary) {
this.saveOrUpdate(previewLibrary);
//         this.save(previewLibrary);
}
最后效果是这个
 struts2中的action取到了值,但插入不到数据库中,求助
报的错有这些
 struts2中的action取到了值,但插入不到数据库中,求助
还有java.lang.illegalStateException
org.hibernate.genericJDBCException,如果还需要什么我可以继续上传,真心求助,全部积分了!


解决方案1:

previed_id 数据库是非空的,而你又没有为其赋值,所以爆掉了。
一般将previed_id做自增长就可以了(逻辑主键)。

解决方案2:

previewId 你这个没有赋值,而且这个字段在数据库表中是非空的,没有默认值,所以报错

解决方案3:

Hibernate的xml配置文件中关于主键生成策略可能没写对,检查下previewId的属性配置。


以上介绍了“ struts2中的action取到了值,但插入不到数据库中,求助”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/2835768.html

相关图片

相关文章