diff --git a/code/ReportDaoImpl.java b/code/ReportDaoImpl.java new file mode 100644 index 0000000..7c81c63 --- /dev/null +++ b/code/ReportDaoImpl.java @@ -0,0 +1,58 @@ +package com.dao; +import java.util.*; + + +import java.util.Date; +import java.sql.*; + +import com.domain.Article; +import com.domain.Report; + +public class ReportDaoImpl implements ReportDao { + + @Override + public List listReport() throws SQLException { + // TODO Auto-generated method stub + Report Report = new Report(); + Connection conn = getConnection(); + List list = new ArrayList(); + String sql = "SELECT * FROM Report"; + try( + PreparedStatement pstmt = conn.prepareStatement(sql); + ResultSet rs = pstmt.executeQuery()){ + while(rs.next()){ + Report.setRid(rs.getInt("Rid")); + Report.setUid(rs.getString("Uid")); + Report.setRdate(rs.getDate("Rdate")); + Report.setResult(rs.getString("Result")); + Report.setCompany(rs.getString("Company")); + Report.setRpicture(rs.getBytes("Rpicture")); + list.add(Report); + } + return list; + }catch(SQLException e){ + System.out.println(e); + return null; + } + + } + + @Override + public int removeReport(int Rid) throws SQLException { + // TODO Auto-generated method stub + Connection conn = getConnection(); + String sql = "DELETE FROM Report WHERE Rid=?"; + try{ + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, Rid); + return pstmt.executeUpdate(); + }catch(SQLException sqle){ + System.out.print(sqle); + return 0; + } + } + + + +} +