日期:2014-05-17 浏览次数:20776 次
/* *网站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(" "," "); 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; } }