From ba75e41c239d819182086c3559564f201371144b Mon Sep 17 00:00:00 2001 From: pfu2aoslz <2269185321@qq.com> Date: Thu, 6 Jan 2022 21:27:38 +0800 Subject: [PATCH] ADD file via upload --- code/AuthorityDaoImpl.java | 98 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 code/AuthorityDaoImpl.java diff --git a/code/AuthorityDaoImpl.java b/code/AuthorityDaoImpl.java new file mode 100644 index 0000000..db93265 --- /dev/null +++ b/code/AuthorityDaoImpl.java @@ -0,0 +1,98 @@ +package com.dao; +import java.util.*; + +import java.util.Date; +import java.sql.*; +import com.domain.Authority; + +public class AuthorityDaoImpl implements AuthorityDao { + + // 随机检索学生方法 +// 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 listAuthority() throws SQLException { + // TODO Auto-generated method stub + Authority Authority = new Authority(); + + Connection conn = getConnection(); + List list = new ArrayList(); + String sql = "SELECT * FROM Authority"; + 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); + Authority.setCid(rs.getInt("Cid")); + Authority.setUid(rs.getString("Uid")); + Authority.setIid(rs.getString("Iid")); + Authority.setProfession(rs.getString("Profession")); + Authority.setCompany(rs.getString("Company")); + Authority.setPicture(rs.getBytes("Picture")); + list.add(Authority); + } + System.out.println(list+"test2"); + return list; + + }catch(SQLException e){ + System.out.println(e); + return null; + } + } + @Override + // 删除动态 + public int removeAuthority(int Cid) throws SQLException { + // TODO Auto-generated method stub + Connection conn = getConnection(); + String sql = "DELETE FROM Authority WHERE Cid=?"; + try { + + PreparedStatement pstmt = conn.prepareStatement(sql); + pstmt.setInt(1, Cid); + return pstmt.executeUpdate(); + }catch(SQLException sqle){ + System.out.println(sqle); + return 0; + } + } + +} + + + + +