parent
595fd39ae1
commit
caaffd9418
@ -0,0 +1,95 @@
|
||||
package com.dao;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.sql.*;
|
||||
import com.domain.PostCheck;
|
||||
|
||||
public class PostCheckDaoImpl implements PostCheckDao {
|
||||
|
||||
// 随机检索学生方法
|
||||
// public PostCheck findDyid(int Dyid) throws DaoException{
|
||||
// String sql="SELECT Dyid,Uid,Uname,Rtime,Content"+"FROM Dynamic WHERE id=?";
|
||||
// PostCheck postcheck = new PostCheck();
|
||||
// try(
|
||||
// Connection conn=getConnection();
|
||||
// PreparedStatement pstmt=conn.prepareStatement(sql)){
|
||||
// pstmt.setInt(1, Dyid);
|
||||
// try(ResultSet rst=pstmt.executeQuery()){
|
||||
// if(rst.next()) {
|
||||
// postcheck.setDyid(rst.getInt("Dyid"));
|
||||
// postcheck.setUid(rst.getString("Uid"));
|
||||
// postcheck.setUname(rst.getString("Uname"));
|
||||
// postcheck.setRtime(rst.getDate("Rtime"));
|
||||
// postcheck.setContent(rst.getString("Content"));
|
||||
// }
|
||||
// }
|
||||
// }catch(SQLException se) {
|
||||
// return null;
|
||||
// }
|
||||
// return postcheck;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public List<PostCheck> listPostCheck() throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
PostCheck postcheck = new PostCheck();
|
||||
|
||||
Connection conn = getConnection();
|
||||
List<PostCheck> list = new ArrayList<PostCheck>();
|
||||
String sql = "SELECT * FROM Dynamic";
|
||||
try (
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
ResultSet rs = pstmt.executeQuery()){
|
||||
System.out.println(rs+"test1");
|
||||
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);
|
||||
postcheck.setDyid(rs.getInt("Dyid"));
|
||||
postcheck.setUid(rs.getString("Uid"));
|
||||
postcheck.setUname(rs.getString("Uname"));
|
||||
postcheck.setRtime(rs.getDate("Rtime"));
|
||||
postcheck.setContent(rs.getString("Content"));
|
||||
list.add(postcheck);
|
||||
}
|
||||
System.out.println(list+"test2");
|
||||
return list;
|
||||
|
||||
}catch(SQLException e){
|
||||
System.out.println(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
// 删除学生
|
||||
public int removePostCheck(int Dyid) throws SQLException {
|
||||
// TODO Auto-generated method stub
|
||||
Connection conn = getConnection();
|
||||
String sql = "DELETE FROM Dynamic WHERE Dyid=?";
|
||||
try {
|
||||
|
||||
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setInt(1, Dyid);
|
||||
return pstmt.executeUpdate();
|
||||
}catch(SQLException sqle){
|
||||
System.out.println(sqle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue