parent
af99cc36b3
commit
fd8108b2f9
@ -0,0 +1,92 @@
|
|||||||
|
package com.dao;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
import com.domain.Doctor;
|
||||||
|
|
||||||
|
public class DoctorDaoImpl implements DoctorDao {
|
||||||
|
|
||||||
|
// 添加学生方法
|
||||||
|
public boolean addDoctor(Doctor s)throws SQLException{
|
||||||
|
Connection conn = getConnection();
|
||||||
|
String sql = "INSERT INTO Doctor(Doid,Dname,Dsex,Dnation,Dposition,Didcard,Dpmtname,Dpmtid,Dtel,Daddress) VALUES (?,?,?,?,?,?,?,?,?,?)";
|
||||||
|
try{
|
||||||
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||||
|
pstmt.setInt(1, s.getDoid());
|
||||||
|
pstmt.setString(2, s.getDname());
|
||||||
|
pstmt.setString(3, s.getDsex());
|
||||||
|
pstmt.setString(4, s.getDnation());
|
||||||
|
pstmt.setString(5, s.getDposition());
|
||||||
|
pstmt.setString(6,s.getDidcard());
|
||||||
|
pstmt.setString(7, s.getDpmtname());
|
||||||
|
pstmt.setString(8, s.getDpmtid());
|
||||||
|
pstmt.setString(9,s.getDtel());
|
||||||
|
pstmt.setString(10,s.getDaddress());
|
||||||
|
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
return true;
|
||||||
|
}catch(SQLException sqle){
|
||||||
|
System.out.println(sqle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 检索学生方法
|
||||||
|
public List<Doctor> listDoctor()throws SQLException{
|
||||||
|
Connection conn = getConnection();
|
||||||
|
String sql = "SELECT * FROM Doctor";
|
||||||
|
List<Doctor> list = new ArrayList<Doctor>();
|
||||||
|
try{
|
||||||
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||||
|
ResultSet rs = pstmt.executeQuery();
|
||||||
|
while(rs.next()){
|
||||||
|
int Did = rs.getInt("Doid");
|
||||||
|
String Dname = rs.getString(2);
|
||||||
|
String Dsex = rs.getString(3);
|
||||||
|
String Dnation = rs.getString(4);
|
||||||
|
String Dposition = rs.getString(5);
|
||||||
|
String Didcard = rs.getString(6);
|
||||||
|
String Dpmtname = rs.getString(7);
|
||||||
|
String Dpmtid = rs.getString(8);
|
||||||
|
String Dtel = rs.getString(9);
|
||||||
|
String Daddress = rs.getString(10);
|
||||||
|
Doctor s = new Doctor();
|
||||||
|
s.setDoid(Did);
|
||||||
|
s.setDname(Dname);
|
||||||
|
s.setDsex(Dsex);
|
||||||
|
s.setDnation(Dnation);
|
||||||
|
s.setDposition(Dposition);
|
||||||
|
s.setDidcard(Didcard);
|
||||||
|
s.setDpmtname(Dpmtname);
|
||||||
|
s.setDpmtid(Dpmtid);
|
||||||
|
s.setDsex(Dsex);
|
||||||
|
s.setDtel(Dtel);
|
||||||
|
s.setDaddress(Daddress);
|
||||||
|
list.add(s);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}catch(SQLException sqle){
|
||||||
|
System.out.println(sqle);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 删除医生
|
||||||
|
public int deleteDoctor(int id)throws SQLException{
|
||||||
|
Connection conn = getConnection();
|
||||||
|
String sql = "DELETE FROM Doctor WHERE doid=?";
|
||||||
|
try{
|
||||||
|
PreparedStatement pstmt = conn.prepareStatement(sql);
|
||||||
|
pstmt.setInt(1, id);
|
||||||
|
return pstmt.executeUpdate();
|
||||||
|
}catch(SQLException sqle){
|
||||||
|
System.out.println(sqle);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue