两颗大白菜 2017-05-31 09:44 采纳率: 0%
浏览 604

sqlserver 2005执行数据库更新操作时,控制台没有报错,也没有更新成功,到底是什么问题呀

有一个jsp页面用来展示数据库商品信息的,通过点击每一条记录后边的修改按钮跳转到修改页面,在修改页面先获取要修改的那个商品的信息,除了id不可改,其他内容是可改变的,点击修改页面的修改按钮,将这个修改表单提交到action类处理,在action类中调用update方法,update方法是在itemDao.java里边定义的。

以下是我的个文件代码:
1.原展示商品页面的代码:
图片说明
2.修改页面代码
图片说明

3.action类代码:

public class uploadttAction extends ActionSupport {
private File uploadtt;
private String uploadttContentType;
private String uploadttFileName;
private String result;
private String className;

public String getClassName() {
    return className;
}

public void setClassName(String className) {
    this.className= className;
}

private int id; // 产品编号
private String name; // 产品名称
private String huohao;//产品货号    
private int price; // 产品价格
private String pic; // 产品图片
private String descri; // 产品描述
private String form; //组件

public int getId() {
    return id;
}

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

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getHuohao() {
    return huohao;
}
public void setHuohao(String huohao) {
    this.huohao = huohao;
}

public int getPrice() {
    return price;
}

public void setPrice(int price) {
    this.price = price;
}

public String getForm() {
    return form;
}

public void setForm(String form) {
    this.form = form;
}

public String getPic() {
    return pic;
}

public void setPic(String pic) {
    this.pic = pic;
}

public String getDescri() {
    return descri;
}

public void setDescri(String descri) {
    this.descri = descri;
}

public File getUploadtt() {
    return uploadtt;
}

public void setUploadtt(File upload) {
    this.uploadtt = upload;
}

public String getUploadttContentType() {
    return uploadttContentType;
}

public void setUploadttContentType(String uploadContentType) {
    this.uploadttContentType = uploadContentType;
}

public String getUploadttFileName() {
    return uploadttFileName;
}

public void setUploadttFileName(String uploadFileName) {
    this.uploadttFileName = uploadFileName;
}

public String getResult() {
    return result;
}

public void setResult(String result) {
    this.result = result;
}

// 实现execute方法
public String execute() throws Exception {
    HttpServletRequest reqeust = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();

        String path = ServletActionContext.getServletContext().getRealPath(
                "/img");
        File file = new File(path);
        if (!file.exists()) {
            file.mkdir();

        }
        FileUtils.copyFile(uploadtt, new File(file, uploadttFileName));
        result = "上传成功";

        item n = new item();
        itemDao iDao = new itemDao();

        //int id = Integer.parseInt(reqeust.getParameter("id"));
        String className = reqeust.getParameter("className");
        String name = (String) reqeust.getParameter("name");
        String huohao = (String) reqeust.getParameter("aNumber");
        String form = (String) reqeust.getParameter("component");
        String descri = (String) reqeust.getParameter("descri");
        int price = Integer.parseInt(reqeust.getParameter("price"));
        String pic = "img/" + uploadttFileName; // 获取表单传过来的数据

        n.setClassName(className);
        n.setName(name);
        n.setHuohao(huohao);
        n.setForm(form);
        n.setDescri(descri);
        n.setPrice(price);
        n.setPic(pic);

        try {
            iDao.updateItem(n);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    //}

    return SUCCESS;

}

}


4.Dao类代码:
public void updateItem(item item) throws SQLException {
Connection conn = DBUtil.getConnection();
try {
String sql ="update item set className=?,name=?,huohao=?,form=?,descri=?,pic=?,price=? where id=?";
PreparedStatement ptmt = conn.prepareStatement(sql);

    ptmt.setString(1, item.getClassName());
    ptmt.setString(2, item.getName());
    ptmt.setString(3, item.getHuohao());
    ptmt.setString(4, item.getForm());
    ptmt.setString(5, item.getDescri());
    ptmt.setString(6, item.getPic());
    ptmt.setInt(7, item.getPrice());
    ptmt.setInt(8, item.getId());
    ptmt.executeUpdate();
} catch (Exception e) {
    e.printStackTrace();
}

}


  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-20 23:57
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序