You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
teeth/code/AuthorityDaoImpl.java

99 lines
2.9 KiB

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<Authority> listAuthority() throws SQLException {
// TODO Auto-generated method stub
Authority Authority = new Authority();
Connection conn = getConnection();
List<Authority> list = new ArrayList<Authority>();
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;
}
}
}