新闻发布系统
}
} }
} catch (SQLException e) { e.printStackTrace(); } }
3.2 新闻浏览
功能:通过点击新闻查看新闻的详细内容 实现:点击新闻后根据新闻ID查询出新闻详细内容,封装至新闻的JavaBean中,传至JSP页面,取出数据显示 public News getNewsDetail(String news_id){ News news = new News(); try {
con = DBConnector.getConnection();
ps = con.prepareStatement("select * from news where news_id=?");
ps.setString(1, news_id); rs = ps.executeQuery(); while(rs.next()){
news.setNews_id(rs.getInt(1));
news.setNews_type(rs.getString(2)); news.setNews_keys(rs.getString(3)); news.setNews_author(rs.getString(4)); news.setNews_origin(rs.getString(5)); news.setNews_content(rs.getString(6)); news.setNews_title(rs.getString(7)); news.setNews_read(rs.getShort(8)); news.setNews_time(rs.getString(9)); }
ps = con.prepareStatement("update news set news_read=? where news_id=?");
ps.setInt(1, news.getNews_read()+1);//将阅读次数加1 ps.setString(2, news_id); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); }finally{
DBConnector.free(rs, ps, con); }
return news; }
3.3 新闻管理