package com.bbs.dao;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import com.bbs.entity.Article;
import com.bbs.entity.Comment;
import com.bbs.service.articleService;
import com.bbs.service.commentService;
import com.bbs.util.DBconnection;
/**
*
* @author hsy
* describe:对文章的操作
*用id查 用name查,查全部文章,修改文章新增文章,删除文章
*/
public class articleDao {
// 用ID获取文章对象
public Article getarticleById(int id) {
Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
String sql = “select idunametitletypecontenttime from article where id = ?“;
try {
conn = DBconnection.getConnection();
ps = conn.prepareStatement(sql);
ps.setInt(1 id);
rs = ps.executeQuery();
if (rs.next()) {
// 如果存在,则直接构建并返回用户对象
Article article = new Article(rs.getInt(“id“)rs.getString(“uname“) rs.getString(“title“) rs.getString(“type“)
rs.getString(“content“) rs.getString(“time“));
conn.commit();
return article;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
//DBconnection.close(rs ps conn);
}
return null;
}
// 按名字查找文章
public Article getarticleByName(String title) {
ResultSet rs = null;
PreparedStatement ps = null;
Connection conn = null;
String sql = “select idunametitletypecontenttime from article where title=? “;
try {
conn = DBconnection.getConnection();
ps = conn.prepareStatement(sql);
ps.setString(1 title);
rs = ps.executeQuery();
if (rs.next()) {
// 如果存在,则直接构建并返回用户对象
Article article = new Article(rs.getInt(“id“) rs.getString(“uname“)rs.getString(“title“) rs.getString(“type“)
rs.getString(“content“) rs.getString(“time“));
conn.commit();
return article;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
//关闭连接
//DBconnection.close(rs ps conn);
}
return null;
}
// 查询所有文章
public List getAllarticles() {
List list = new ArrayList();
ResultSet rs = null;
PreparedStatement ps = null;
Connection conn = null;
String sql = “select idunametitletypecontenttime from article “;
try {
conn = DBconnection.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
// 循环添加用户对象
while (rs.next()) {
Article article = new Article(rs.getInt(“id“)rs.getString(“uname“) rs.getString(“title“) rs.getString(“type“)
rs.getString(“content“) rs.getString(“time“));
list.add(article);
}
conn.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
//DBconnection.close(rs ps conn);
}
return list;
}
// 查询所有文章(分页)
public List getAllarticles(int startIndexint pageSize) {
List list = new ArrayLis
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1009 2018-12-10 22:23 newBBS\.classpath
文件 906 2018-11-27 22:10 newBBS\.project
文件 567 2018-11-27 22:10 newBBS\.settings\.jsdtscope
文件 57 2018-11-29 10:36 newBBS\.settings\org.eclipse.core.resources.prefs
文件 364 2018-11-30 09:24 newBBS\.settings\org.eclipse.jdt.core.prefs
文件 470 2018-11-27 22:10 newBBS\.settings\org.eclipse.wst.common.component
文件 345 2018-12-10 22:23 newBBS\.settings\org.eclipse.wst.common.project.facet.core.xm
l
文件 49 2018-11-27 22:10 newBBS\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2018-11-27 22:10 newBBS\.settings\org.eclipse.wst.jsdt.ui.superType.name
文件 5521 2018-12-13 10:36 newBBS\bbs.sql
文件 5919 2018-12-19 22:23 newBBS\build\classes\com\bbs\dao\articleDao.class
文件 3830 2018-12-19 22:23 newBBS\build\classes\com\bbs\dao\commentDao.class
文件 5727 2018-12-19 22:23 newBBS\build\classes\com\bbs\dao\userDao.class
文件 153 2018-11-28 22:40 newBBS\build\classes\com\bbs\DBconfig.properties
文件 1070 2018-12-19 22:23 newBBS\build\classes\com\bbs\entity\Admin.class
文件 1745 2018-12-19 22:23 newBBS\build\classes\com\bbs\entity\Article.class
文件 1491 2018-12-19 22:23 newBBS\build\classes\com\bbs\entity\Comment.class
文件 1509 2018-12-19 22:23 newBBS\build\classes\com\bbs\entity\User.class
文件 1720 2018-12-19 22:23 newBBS\build\classes\com\bbs\entity\vo\comment_userVO.class
文件 1875 2018-12-19 22:23 newBBS\build\classes\com\bbs\service\articleService.class
文件 1071 2018-12-19 22:23 newBBS\build\classes\com\bbs\service\commentService.class
文件 2260 2018-12-19 22:23 newBBS\build\classes\com\bbs\service\userService.class
文件 2274 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\adminLogin.class
文件 1323 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\adminLogout.class
文件 2679 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\articleContent.class
文件 2247 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\changeAuthorization.class
文件 1980 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\deleteComment.class
文件 1793 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\deleteData.class
文件 1700 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\filter0_encodingFilter.class
文件 2780 2018-12-19 22:23 newBBS\build\classes\com\bbs\servlet\filter1_initFilter.class
............此处省略432个文件信息
评论
共有 条评论