parent
19b771e0c1
commit
f6283943cf
@ -0,0 +1,75 @@
|
||||
package com.dao;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.sql.*;
|
||||
import com.domain.Article;
|
||||
|
||||
public class ArticleDaoImpl implements ArticleDao {
|
||||
|
||||
|
||||
@Override
|
||||
public List<Article> listArticle() throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
Article Article = new Article();
|
||||
|
||||
Connection conn = getConnection();
|
||||
List<Article> list = new ArrayList<Article>();
|
||||
String sql = "SELECT * FROM Article";
|
||||
try (
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = pstmt.executeQuery()){
|
||||
while(rs.next()){
|
||||
// int Dyid = rs.getInt("Dyid");
|
||||
// String Uid = rs.getString(2);
|
||||
// String Uname = rs.getString(3);
|
||||
// Date Rtime = rs.getDate(4);
|
||||
// String Content = rs.getString(5);
|
||||
// PostCheck s = new PostCheck();
|
||||
// s.setDyid(Dyid);
|
||||
// s.setUid(Uid);
|
||||
// s.setUname(Uname);
|
||||
// s.setRtime(Rtime);
|
||||
// s.setContent(Content);
|
||||
// System.out.println(list+"test2");//
|
||||
// list.add(s);
|
||||
Article.setAid(rs.getInt("Aid"));
|
||||
Article.setUid(rs.getString("Uid"));
|
||||
Article.setUname(rs.getString("Uname"));
|
||||
Article.setTitle(rs.getString("Title"));
|
||||
Article.setContent(rs.getString("Content"));
|
||||
Article.setMid(rs.getString("Mid"));
|
||||
Article.setDate(rs.getDate("date"));
|
||||
Article.setStatics(rs.getString("Statics"));
|
||||
list.add(Article);
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}catch(SQLException e){
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
// 删除文章
|
||||
public int removeArticle(int Aid) throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
Connection conn = getConnection();
|
||||
String sql = "DELETE FROM Article WHERE Aid=?";
|
||||
try {
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setInt(1, Aid);
|
||||
return pstmt.executeUpdate();
|
||||
}catch(SQLException sqle){
|
||||
System.out.println(sqle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue