新闻发布系统(struts + SQL Server 2000)

  • u3_394382
    了解作者
  • 1.9MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-31 02:52
    上传日期
用到了validate、验证码。 非常适合初学者学习,里面的路径很复杂,有利于学习借鉴。
mynews.rar
内容介绍
package com.news.struts.tools; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.news.struts.domain.NewsActionForm; public class NewsOperate { public List newsList(){ DBAccess db = new DBAccess(); List list = new ArrayList(); NewsActionForm naf = null; String sql = "select * from tb_news"; try{ ResultSet rs = db.executeQuery(sql); while(rs.next()){ naf = new NewsActionForm(); naf.setNewID(rs.getInt("ID")); naf.setNewTitle(rs.getString("Title")); naf.setNewsType(rs.getString("Type")); naf.setNewsStyle(rs.getString("Style")); naf.setNewIssueDate(rs.getString("IssDate")); list.add(naf); } }catch(SQLException e ){ e.printStackTrace(); } return list; } public void newsDelete(int id){ DBAccess db = new DBAccess(); String sql = "delete from tb_news where ID='"+id+"'"; int result = db.executeUpdate(sql); } public boolean addNews(String title,String content,String type,String style){ DBAccess db = new DBAccess(); boolean success = false; int num = 0; int result = 0; Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try{ String sql1 = "select max(ID) as maxID from tb_news"; ResultSet rs = db.executeQuery(sql1); if(rs.next()){ num = rs.getInt("maxID")+1; } }catch(SQLException e){ e.printStackTrace(); } String sql2 = "insert into tb_news(ID,Title,Content,Type,Style,IssDate) values ('"+num+"','"+title+"','"+content+"','"+type+"','"+style+"','"+sdf.format(d)+"')"; result = db.executeUpdate(sql2); if(result!=0){ success = true; } return success; } public List content(int id){ DBAccess db = new DBAccess(); NewsActionForm naf = null; List list = new ArrayList(); String sql = "select * from tb_news where ID='"+id+"'"; try{ ResultSet rs = db.executeQuery(sql); if(rs.next()){ naf = new NewsActionForm(); naf.setNewID(rs.getInt("ID")); naf.setNewTitle(rs.getString("Title")); naf.setNewContent(rs.getString("Content")); naf.setNewsType(rs.getString("Type")); naf.setNewsStyle(rs.getString("Style")); list.add(naf); } }catch(SQLException e){ e.printStackTrace(); } return list; } public void newsAlter(int id,String title,String content,String type,String style){ DBAccess db = new DBAccess(); Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sql = "update tb_news set Title = '"+title+"' ,Content='"+content+"' ,Type='"+type+"' ,Style='"+style+"' , IssDate='"+sdf.format(d)+"' where ID='"+id+"'"; int result = db.executeUpdate(sql); } public List showNewsOfType(String type){ DBAccess db = new DBAccess(); List list = new ArrayList(); NewsActionForm naf = null; String sql = "select * from tb_news where Type = '"+type+"'"; try{ ResultSet rs = db.executeQuery(sql); while(rs.next()){ naf = new NewsActionForm(); naf.setNewID(rs.getInt("ID")); naf.setNewTitle(rs.getString("Title")); naf.setNewsStyle(rs.getString("Style")); naf.setNewIssueDate(rs.getString("IssDate")); list.add(naf); } }catch(SQLException e ){ e.printStackTrace(); } return list; } public List readNews(int id){ DBAccess db = new DBAccess(); List list = new ArrayList(); NewsActionForm naf = null; String sql = "select * from tb_news where ID = '"+id+"'"; try{ ResultSet rs = db.executeQuery(sql); while(rs.next()){ naf = new NewsActionForm(); naf.setNewTitle(rs.getString("Title")); naf.setNewContent(rs.getString("Content")); naf.setNewsType(rs.getString("Type")); naf.setNewsStyle(rs.getString("Style")); naf.setNewIssueDate(rs.getString("IssDate")); list.add(naf); } }catch(SQLException e ){ e.printStackTrace(); } return list; } public List search(String key,String type){ DBAccess db = new DBAccess(); List list = new ArrayList(); NewsActionForm naf = null; try{ String sql = "select * from tb_news where Content like'%"+key+"%' and Type='"+type+"'"; ResultSet rs = db.executeQuery(sql); while(rs.next()){ naf = new NewsActionForm(); naf.setNewID(rs.getInt("ID")); naf.setNewTitle(rs.getString("Title")); naf.setNewsType(rs.getString("Type")); naf.setNewsStyle(rs.getString("Style")); naf.setNewIssueDate(rs.getString("IssDate")); list.add(naf); } db.close(); }catch(SQLException e){ e.printStackTrace(); } return list; } }
评论
    相关推荐