当前位置: 代码迷 >> Java Web开发 >> 简单的更改记录的语句?解决方案
  详细解决方案

简单的更改记录的语句?解决方案

热度:7579   发布时间:2013-02-25 21:19:13.0
简单的更改记录的语句?
JAVABEAN功能:添加一条新记录.并按新记录的style(分类)把stylelist表中相同style(分类)的cou加1.
分不多了.谢谢各位帮帮忙!
Java code
/* *网站JAVABEAN *添加一条新信息, *添加成功显示提示及继续添加的链接. *前台页面 */package mybean;import java.sql.*;public class Publish {        private PreparedStatement pstmt = null;    private Statement stmt = null;         private Connection conn = null;    private String city;    private String title;    private String style;    private String content;    private String pass;    private String chec;    private String addMessage;            public Publish(){}        public void setCity(String city){        this.city=city;    }    public void setTitle(String title){        this.title=title;           }    public void setStyle(String style){        this.style=style;    }    public void setContent(String content){        //替换HTML字符输出的格式        content=content.replace("\n","<BR/>");        content=content.replace(" ","&nbsp;");        this.content=content;    }    public void setPass(String pass){        this.pass=pass;    }    public void setChec(String chec){        this.chec=chec;    }        public String getCity(){        return this.city;    }    public String getTitle(){        return this.title;    }    public String getStyle(){        return this.style;    }    public String getContent(){        return this.content;    }    public String getPass(){        return this.pass;    }    public String getChec(){        return this.chec;    }    public String getAddMessage(){        conn = DBConnSource.getConnection("jdbc/myweb");                   try{         String sql="INSERT INTO adver VALUES(?,?,?,?,?,?,?,?)";           pstmt = DBConnSource.getPstmt(conn,sql);        java.util.Date date=new java.util.Date();        Timestamp tt=new Timestamp(date.getTime());        pstmt.setInt(1,0);        pstmt.setString(2,city);        pstmt.setString(3,style);        pstmt.setString(4,title);        pstmt.setString(5,content);        pstmt.setTimestamp(6,tt);        pstmt.setString(7,pass);        pstmt.setString(8,chec);                int flag=pstmt.executeUpdate();        if(flag>0){            addMessage="成功添加"+flag+"条记录!";            String sql2="UPDATE stylelist SET cou=cou+1 WHERE style='"+style+"'";                       stmt.executeUpdate(sql2); //这一句是Publish.java:89            }else{                addMessage="添加记录失败";            }      }catch(SQLException e) {        e.printStackTrace();    }finally{        DBConnSource.close(stmt);        DBConnSource.close(pstmt);        DBConnSource.close(conn);    }                        return addMessage;    }}

报错:
exception 

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

java.lang.NullPointerException
mybean.Publish.getAddMessage(Publish.java:89)
org.apache.jsp.publish2_jsp._jspService(publish2_jsp.java:139)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)




------解决方案--------------------------------------------------------
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Thu Nov 23 11:44:59 CST 2017
  • 最近登录:Thu Nov 23 11:44:59 CST 2017
  • 最近登录:Thu Nov 23 11:44:59 CST 2017
  • 最近登录:Thu Nov 23 11:44:59 CST 2017
  • 最近登录:Thu Nov 23 11:44:59 CST 2017