package news.db;
import news.db.*;
import news.form.*;
import java.sql.*;
import java.util.*;
public class NewsDAO{
public int insert(News n){
Connection con = null;
int k=0;
PreparedStatement pstmt = null;
String sql = "";
sql = "insert into news(title,author,content,pubtime)values(?,?,?,now())";
try{
con = DatabaseConnection.getCon();
pstmt = con.prepareStatement(sql);
pstmt.setString(1,n.getTitle());
pstmt.setString(2,n.getAuthor());
pstmt.setString(3,n.getContent());
k=pstmt.executeUpdate();
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return k;
}
public ArrayList searchAll(){
Connection con = null;
PreparedStatement pstmt = null;
String sql = "";
ResultSet rs = null;
News n=null;
sql = "select * from news";
ArrayList ar = new ArrayList();
try{
con = DatabaseConnection.getCon();
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
n = new News();
n.setTitle(rs.getString("title"));
n.setAuthor(rs.getString("author"));
n.setContent(rs.getString("content"));
n.setPubtime(rs.getDate("pubtime"));
n.setId(rs.getInt("id"));
ar.add(n);
}
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return ar;
}
public int delete(String aa){
Connection con = null;
int k=0;
PreparedStatement pstmt = null;
String sql = "";
sql = "delete from news where id=?";
try{
con = DatabaseConnection.getCon();
pstmt = con.prepareStatement(sql);
pstmt.setString(1,aa);
k=pstmt.executeUpdate();
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return k;
}
public News search(String id){
Connection con = null;
PreparedStatement pstmt = null;
String sql = "";
ResultSet rs = null;
News u = new News();
sql = "select * from news where id=?";
try{
con = DatabaseConnection.getCon();
pstmt = con.prepareStatement(sql);
pstmt.setString(1,id);
rs = pstmt.executeQuery();
if(rs.next()){
u.setId(rs.getInt("id"));
u.setTitle(rs.getString("title"));
u.setAuthor(rs.getString("author"));
u.setContent(rs.getString("content"));
u.setPubtime(rs.getDate("pubtime"));
}
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return u;
}
public int update(News u){
Connection con = null;
int k=0;
PreparedStatement pstmt = null;
String sql = "";
sql = "update news set title=?,author=?,content=? where id=?";
try{
con = DatabaseConnection.getCon();
pstmt = con.prepareStatement(sql);
pstmt.setString(1,u.getTitle());
pstmt.setString(2,u.getAuthor());
pstmt.setString(3,u.getContent());
pstmt.setInt(4,u.getId());
k=pstmt.executeUpdate();
}catch(Exception e){e.printStackTrace();
}
finally{
try{
if(con!=null){
con.close();
}
}catch(Exception e2){}
}
return k;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JSP+Struts新闻发布系统
共29个文件
jar:11个
class:5个
java:5个
5星 · 超过95%的资源 需积分: 9 172 下载量 190 浏览量
2008-12-18
11:28:47
上传
评论 6
收藏 2.06MB RAR 举报
温馨提示
本新闻发布系统包含了新闻发布,新闻管理等诸多实用功能,纯净无赘余。用户界面友好,管理方便。是当今最实用的新闻发布系统。希望大家能够喜欢。
资源详情
资源评论
资源推荐
收起资源包目录
.rar (29个子文件)
newsss
allnews.jsp 757B
addnews.htm 366B
WEB-INF
news.sql 179B
web.xml 1KB
classes
news
form
News.class 1KB
filter
EncodingFilter.class 843B
action
NewsAction.class 2KB
db
DatabaseConnection.class 976B
NewsDAO.class 4KB
EncodingFilter.java 564B
NewsAction.java 3KB
DatabaseConnection.java 480B
News.java 923B
NewsDAO.java 4KB
struts-config.xml 882B
lib
mysql-connector-java-5.0.0-beta-bin.jar 464KB
commons-beanutils.jar 184KB
jakarta-oro.jar 64KB
standard.jar 384KB
commons-validator.jar 82KB
commons-fileupload.jar 22KB
jstl.jar 20KB
commons-logging.jar 37KB
struts.jar 531KB
antlr.jar 350KB
commons-digester.jar 164KB
tip.jsp 245B
index.htm 207B
news.jsp 604B
共 29 条
- 1
javagxc
- 粉丝: 103
- 资源: 43
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5