package db;
import java.sql.*;
import java.util.*;
import data.*;
public class NewsMgr
{
java.sql.Connection con = null;
java.sql.PreparedStatement pst = null;
java.sql.ResultSet res = null;
java.sql.Statement st=null;
//1.添加新闻
public int Add(News b)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
pst=con.prepareStatement("insert into news values(?,?,?,?,?,?,?)");
pst.setString(1,b.getTopic());
pst.setString(2,b.getContent());
pst.setInt(3,b.getHits());
pst.setInt(4,b.getCategoryid());
pst.setString(5,b.getPicture());
pst.setDate(6,b.getPublishtime());
pst.setString(7,b.getPublishuser());
iVal=pst.executeUpdate();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//1.添加新闻(重写)
public int Add(String Topic,String Content,int Cid,String author)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
st=con.createStatement();
String sVal="insert into news(topic,content,categoryid,publishuser) values('"+Topic+"','"+Content+"','"+Cid+"','"+author+"')";
iVal=st.executeUpdate(sVal);
st.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//2.修改新闻
public int Update (News b)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
String sVal="update news set topic=?,content=?,hits=?,"
+"categoryid=?,picture=?,publishtime=?,publishuser=? "
+"where id=?";
pst=con.prepareStatement(sVal);
pst.setString(1,b.getTopic());
pst.setString(2,b.getContent());
pst.setInt(3,b.getHits());
pst.setInt(4,b.getCategoryid());
pst.setString(5,b.getPicture());
pst.setDate(6,b.getPublishtime());
pst.setString(7,b.getPublishuser());
iVal=pst.executeUpdate();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//2.修改新闻(重写)
public int Update (int id,String topic,String content,int cid,String author)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
String sVal="update news set topic=?,content=?,categoryid=?,publishuser=? where id=?";
pst=con.prepareStatement(sVal);
pst.setString(1,topic);
pst.setString(2,content);
pst.setInt(3,cid);
pst.setString(4,author);
pst.setInt(5,id);
iVal=pst.executeUpdate();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//3.删除新闻
public int Delete(int id)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
pst=con.prepareStatement("delete from news where id=?");
pst.setInt(1,id);
iVal=pst.executeUpdate();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//4.新闻浏览次数加
public int GetAllBy(int id)
{
con=ConnectionManager.Getcon();
int iVal=0;
try
{
pst=con.prepareStatement("update news set hits=hits+1 where id=?");
pst.setInt(1,id);
iVal=pst.executeUpdate();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return iVal;
}
//5.根据CategoryId得到某栏目所有的新闻
public ArrayList GetNewsByCId(News b)
{
con=ConnectionManager.Getcon();
ArrayList al=new ArrayList();
try
{
String sVal="select * from news where categoryid=?"
+"order by publishtime desc";
pst = con.prepareStatement(sVal);
pst.setInt(1,b.getId());
res=pst.executeQuery();
while(res.next())
{
News objnew=new News();
objnew.setId(res.getInt(1));
objnew.setTopic(res.getString(2));
objnew.setContent(res.getString(3));
objnew.setHits(res.getInt(4));
objnew.setCategoryid(res.getInt(5));
objnew.setPicture(res.getString(6));
objnew.setPublishtime(res.getDate(7));
objnew.setPublishuser(res.getString(8));
al.add(objnew);
}
res.close();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return al;
}
//5.根据CategoryId得到某栏目所有的新闻(重写)
public List GetNewsByCId(int id)
{
con=ConnectionManager.Getcon();
List al=new ArrayList();
try
{
String sVal="select * from news where categoryid=? order by publishtime desc";
pst = con.prepareStatement(sVal);
pst.setInt(1,id);
res=pst.executeQuery();
while(res.next())
{
News objnew=new News();
objnew.setId(res.getInt(1));
objnew.setTopic(res.getString(2));
objnew.setContent(res.getString(3));
objnew.setHits(res.getInt(4));
objnew.setCategoryid(res.getInt(5));
objnew.setPicture(res.getString(6));
objnew.setPublishtime(res.getDate(7));
objnew.setPublishuser(res.getString(8));
al.add(objnew);
}
res.close();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return al;
}
//5.根据CategoryId得到某栏目的前6个新闻
public List GetNewsSix(int id)
{
con=ConnectionManager.Getcon();
List al=new ArrayList();
try
{
String sVal="select top 6 * from news where categoryid=? order by publishtime desc";
pst = con.prepareStatement(sVal);
pst.setInt(1,id);
res=pst.executeQuery();
while(res.next())
{
News objnew=new News();
objnew.setId(res.getInt(1));
objnew.setTopic(res.getString(2));
objnew.setContent(res.getString(3));
objnew.setHits(res.getInt(4));
objnew.setCategoryid(res.getInt(5));
objnew.setPicture(res.getString(6));
objnew.setPublishtime(res.getDate(7));
objnew.setPublishuser(res.getString(8));
al.add(objnew);
}
res.close();
pst.close();
con.close();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
return al;
}
//6.根据ID得到新闻
public List GetAllById(int id)
{
con=ConnectionManager.Getcon();
List lt=new ArrayList();
try
{
pst = con.prepareStatement("select * from news where id=?");
没有合适的资源?快使用搜索试试~ 我知道了~
jsp新闻发布系统 java
共637个文件
class:89个
java:70个
jsp~1~:37个
3星 · 超过75%的资源 需积分: 12 3 下载量 125 浏览量
2008-12-29
22:29:03
上传
评论
收藏 1.15MB RAR 举报
温馨提示
新闻发布系统 sql2000数据库 java
资源详情
资源评论
资源推荐
收起资源包目录
jsp新闻发布系统 java (637个子文件)
NewsManage_jsp.class 11KB
MasterManage_jsp.class 11KB
NewsManage_jsp.class 10KB
LeaveWordInfo_jsp.class 10KB
NewsManage1_jsp.class 10KB
MasterManage_jsp.class 10KB
CategoryManage_jsp.class 9KB
NewsMgr.class 9KB
NewsMgr.class 9KB
NewsText_jsp.class 9KB
NewsContent_jsp.class 9KB
NewsManage1_jsp.class 9KB
LeaveWordInfo_jsp.class 9KB
CategoryManage_jsp.class 8KB
NewsEdit_jsp.class 8KB
NewsSearch_jsp.class 8KB
NewsText_jsp.class 8KB
NewsContent_jsp.class 8KB
NewsAdd_jsp.class 7KB
MasterMgr.class 7KB
MasterMgr.class 7KB
NewsEdit_jsp.class 7KB
MasterEdit_jsp.class 7KB
MasterLogin_jsp.class 6KB
MasterLogin_jsp.class 6KB
NewsAdd_jsp.class 6KB
Center_jsp.class 6KB
NewsHomepage_jsp.class 6KB
NewsLeaveWord_jsp.class 5KB
CategoryAdd_jsp.class 5KB
Center_jsp.class 5KB
NewsHomepage_jsp.class 5KB
CategoryEdit_jsp.class 5KB
Right_jsp.class 5KB
NewsLeaveWord_jsp.class 5KB
Left_jsp.class 5KB
Right_jsp.class 5KB
CategoryAdd_jsp.class 4KB
Topic4_jsp.class 4KB
LeaveWordAdd_jsp.class 4KB
Topic3_jsp.class 4KB
Left_jsp.class 4KB
MasterLoginDelServlet.class 4KB
MasterLoginDelServlet.class 4KB
Topic4_jsp.class 4KB
Topic3_jsp.class 4KB
CategoryMgr.class 4KB
CategoryMgr.class 4KB
Topic1_jsp.class 4KB
Topic1_jsp.class 4KB
Bottom_jsp.class 3KB
VerifyNewPasswordServlet.class 3KB
VerifyNewPasswordServlet.class 3KB
Topic5_jsp.class 3KB
Bottom_jsp.class 3KB
HBottom_jsp.class 3KB
Topic5_jsp.class 3KB
Topic2_jsp.class 3KB
Exit_jsp.class 3KB
Error_jsp.class 3KB
Error_jsp.class 3KB
NewsEditDelServlet.class 3KB
NewsEditDelServlet.class 3KB
LeaveWordMgr.class 3KB
LeaveWordMgr.class 3KB
NewsAddServlet.class 2KB
NewsAddServlet.class 2KB
LoginManageServlet.class 2KB
LoginManageServlet.class 2KB
CategoryEditServlet.class 2KB
CategoryEditServlet.class 2KB
PageBean.class 2KB
PageBean.class 2KB
CategoryAddServlet.class 2KB
CategoryAddServlet.class 2KB
PageServlet.class 2KB
PageServlet.class 2KB
CategoryDeleteServlet.class 2KB
CategoryDeleteServlet.class 2KB
News.class 2KB
News.class 2KB
Master.class 2KB
Master.class 2KB
LeaveWord.class 1KB
LeaveWord.class 1KB
ConnectionManager.class 916B
ConnectionManager.class 916B
Category.class 894B
Category.class 894B
org.apache.jsp.dep2 44KB
org.apache.jsp.Admin.dep2 38KB
Servlets.dep2 16KB
db.dep2 9KB
data.dep2 4KB
show-0430-160x290.gif 24KB
hb-0501-160x290.gif 12KB
44.gif 9KB
logo.gif 2KB
p_title01.gif 1KB
4.gif 1KB
共 637 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
zjutjay
- 粉丝: 0
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 课程设计-python爬虫-爬取日报,爬取日报文章后存储到本地,附带源代码+课程设计报告
- 软件和信息技术服务行业投资与前景预测.pptx
- 课程设计-基于SpringBoot + Mybatis+python爬虫NBA球员数据爬取可视化+源代码+文档+sql+效果图
- 软件品质管理系列二项目策划规范.doc
- 基于TensorFlow+PyQt+GUI的酒店评论情感分析,支持分析本地数据文件和网络爬取数据分析+源代码+文档说明+安装教程
- 软件定义无线电中的模拟电路测试技术.pptx
- 软件开发协议(作为技术开发合同附件).doc
- 软件开发和咨询行业技术趋势分析.pptx
- 软件测试题详解及答案.doc
- 软件漏洞生命周期管理策略.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1