package com.dao; import java.util.*; import java.util.Date; import java.sql.*; import com.domain.Dynamic; public class DynamicDaoImpl implements DynamicDao { // 随机检索学生方法 // 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 listDynamic() throws SQLException { // TODO Auto-generated method stub Dynamic Dynamic = new Dynamic(); Connection conn = getConnection(); List list = new ArrayList(); 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); Dynamic.setDyid(rs.getInt("Dyid")); Dynamic.setUid(rs.getString("Uid")); Dynamic.setUname(rs.getString("Uname")); Dynamic.setRtime(rs.getDate("Rtime")); Dynamic.setContent(rs.getString("Content")); Dynamic.setDpicture(rs.getBytes("Dpicture")); Dynamic.setMid(rs.getString("Mid")); Dynamic.setFavour(rs.getInt("Favour")); list.add(Dynamic); } System.out.println(list+"test2"); return list; }catch(SQLException e){ System.out.println(e); return null; } } @Override // 删除动态 public int removeDynamic(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; } } }