package com.xin.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.xin.bean.NewsBean;
import com.xin.uti.jdbc.JDBC;
public class NewsDao {
/* public List getNewsByTime(){
List<NewsBean> list = new ArrayList<NewsBean>();
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from news order by dates desc");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
list.add(new NewsBean(rs.getInt("id"), rs.getString("title"), rs.getString("author"), rs.getString("newscontent"),
rs.getString("dates"), rs.getInt("count"), rs.getString("lastUpdate"), rs.getString("updater")));
}
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}*/
public NewsBean getNewsById(int id){
NewsBean row = null;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from news where id=?");
ps.setObject(1, id);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
row = new NewsBean(rs.getInt("id"), rs.getString("title"), rs.getString("author"), rs.getString("dates"), rs.getString("lastUpdate"), rs.getString("updater"), rs.getInt("count"), rs.getString("newscontent"));
}
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return row;
}
public int getAddCount(int id){
int flag = 0;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("update news set count=count+1 where id=?");
ps.setObject(1, id);
flag = ps.executeUpdate();
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public int getAddNews(String title,String author,String newscontent){
int flag = 0;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("insert into news(title,author,newscontent,count) values(?,?,?,0)");
ps.setObject(1, title);
ps.setObject(2, author);
ps.setObject(3, newscontent);
flag = ps.executeUpdate();
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public int getUpdateNews(int id,String title,String author,String dates,int count,String newscontent,String lastUpdate,String updater){
int flag = 0;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("update news set title=?,author=?,dates=?,newscontent=?,count=?,lastUpdate=?,updater=? where id=?");
ps.setObject(1, title);
ps.setObject(2, author);
ps.setObject(3, dates);
ps.setObject(4, newscontent);
ps.setObject(5, count);
ps.setObject(6, lastUpdate);
ps.setObject(7, updater);
ps.setObject(8, id);
flag = ps.executeUpdate();
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public int getDeleteNews(int id){
int flag = 0 ;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("delete from news where id=?");
ps.setObject(1, id);
flag = ps.executeUpdate();
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return flag;
}
public boolean getAdminLogin(String username,String password){
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from userinfo where name=? and password=?");
ps.setObject(1, username);
ps.setObject(2, password);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return true;
}
JDBC.getClose();
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
//*******************************一下是分页的显示**************************
public static int pagesize = 10;
//统计记录数
public static int getPageCount(){
int total = 0;//读取数据库中总共数据
int pageCount = 0;//总共页数
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select count(*) from news");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
total = rs.getInt(1);
pageCount = (total-1)/pagesize+1;
}
JDBC.getClose();
} catch (Exception e) {
e.printStackTrace();
}
return pageCount;
}
//courentpageno 当前页
public static List getPageNewsByCount(int currentpageno){
List list = new ArrayList();
int BeginReadCord = (currentpageno-1)*pagesize+1;
int EndReadCord = currentpageno*pagesize;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from (select t.*,rownum no from (select * from news order by count desc)t where rownum<="+EndReadCord+") where no >="+BeginReadCord);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
list.add(new NewsBean(rs.getInt("id"), rs.getString("title"), rs.getString("author"), rs.getString("dates"), rs.getString("lastUpdate"), rs.getString("updater"), rs.getInt("count"), rs.getString("newscontent")));
}
JDBC.getClose();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
public static List getPageNewsByTime(int currentpageno){
List list = new ArrayList();
int BeginReadCord = (currentpageno-1)*pagesize+1;
int EndReadCord = currentpageno*pagesize;
try {
Connection conn = JDBC.getConnection();
PreparedStatement ps = conn.prepareStatement("select * from (select t.*,rownum no from (select * from news order by dates desc)t where rownum<="+EndReadCord+") where no >="+BeginReadCord);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
list.add(new NewsBean(rs.getInt("id"), rs.getString("title"), rs.getString("author"), rs.getString("dates"), rs.getString("lastUpdate"), rs.getString("updater"), rs.getInt("count"), rs.getString("newscontent")));
}
JDBC.getClose();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
servlet+JDBC新闻发布系统,增删改查 分页
共61个文件
java:15个
class:15个
jsp:9个
5星 · 超过95%的资源 需积分: 10 78 下载量 36 浏览量
2012-11-30
11:52:07
上传
评论 3
收藏 1.54MB RAR 举报
温馨提示
一个servlet + JDBC 写的一个新闻发布系统,附带Oracle 数据库,前台用户对新闻的点击查看,后台管理新闻,对新闻的增删改查,附带最基本的数据库分页,Myeclipse9.0 + Tomcat6.0 直接可以用
资源推荐
资源详情
资源评论
收起资源包目录
servlet+JDBC新闻发布系统.rar (61个子文件)
News
.project 1KB
.mymetadata 285B
src
com
xin
uti
jdbc
JDBC.java 2KB
dao
NewsDao.java 6KB
servlet
AdminUpdateNews.java 947B
Meth.java 1KB
AdminExitLogin.java 619B
NewsContent.java 1KB
AdminNewsContent.java 1KB
AdminIndex.java 1KB
AdminAddNewsProcess.java 1KB
NewsIndex.java 1KB
AdminUpdateNewsProcess.java 2KB
AdminLogin.java 1KB
AdminDeleteNews.java 907B
bean
UserBean.java 632B
NewsBean.java 2KB
jdbc.properties 538B
WebRoot
WEB-INF
classes
com
xin
uti
jdbc
JDBC.class 3KB
dao
NewsDao.class 5KB
servlet
AdminUpdateNews.class 2KB
Meth.class 2KB
AdminUpdateNewsProcess.class 2KB
AdminDeleteNews.class 1KB
NewsIndex.class 2KB
AdminNewsContent.class 2KB
AdminLogin.class 2KB
AdminIndex.class 2KB
NewsContent.class 2KB
AdminExitLogin.class 1KB
AdminAddNewsProcess.class 1KB
bean
UserBean.class 1KB
NewsBean.class 3KB
jdbc.properties 538B
lib
classes12.jar 1.52MB
web.xml 5KB
admin
error.jsp 3KB
index_news.jsp 4KB
update_news.jsp 4KB
Login_admin.jsp 3KB
content_news.jsp 3KB
add_news.jsp 3KB
index.jsp 3KB
news_index.jsp 4KB
images
Spacer.gif 4KB
index_top3.gif 17KB
index_bg.gif 284B
index_pic.gif 5KB
index_bottom.gif 1KB
index_top4.gif 8KB
01.gif 28KB
index_top2.gif 12KB
CSS.CSS 617B
index_top1.gif 4KB
news_content.jsp 3KB
META-INF
MANIFEST.MF 36B
css
styles.css 517B
.myeclipse
.settings
org.eclipse.jdt.core.prefs 330B
org.eclipse.core.resources.prefs 97B
.classpath 434B
export.sql 6KB
共 61 条
- 1
IT_Jeff
- 粉丝: 16
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页