日期:2014-05-17 浏览次数:20719 次
public void save()throws Exception { try { String newstheme=form.getNews_theme(); String newsauthor=form.getNews_author(); String newsdate=form.getNews_date(); String newsdetail=form.getNews_detail(); String newsurl=form.getNews_url(); String sql="insert into s_news values('"+newstheme+"','"+newsauthor+"','"+newsdate+"','"+newsdetail+"','"+newsurl+"')"; PreparedStatement pstmt=conn.prepareStatement(sql); pstmt.executeUpdate(sql); pstmt.close(); conn.commit(); conn.close(); } catch(Exception e) { conn.rollback(); throw new Exception(e.getMessage()); } }
public class NewsForm extends ActionForm{ private String news_id; private String news_theme; public String getNews_id() { return news_id; } public void setNews_id(String news_id) { this.news_id = news_id; } public String getNews_theme() { return news_theme; } public void setNews_theme(String news_theme) { this.news_theme = news_theme; }
public ActionForward addnews(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) { NewsForm AllNewsActionForm=(NewsForm)form; DataSource ds = getDataSource(request,"struts"); try { ActionNews actionNews= new ActionNews(AllNewsActionForm,ds); actionNews.save(); request.setAttribute("info","保存成功!"); } catch(Exception e) { request.setAttribute("info",e.getMessage()); } return mapping.findForward("save"); }