📄 headdoctor.java
字号:
package bean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
public class HeadDoctor {
private Connection conn;
private Statement stmt;
public HeadDoctor() throws Exception {
conn = DriverManager.getConnection(
"jdbc:sqlserver://localhost;database=hospital", "sa", "1");
conn.setAutoCommit(false);
stmt = conn.createStatement();
System.out.println("建立连接成功!");
}
public Patient getPatient(String patientid) throws SQLException {
ResultSet ret = stmt
.executeQuery("select* from patient where patientid ='"
+ patientid + "'");
if (!ret.next()) {
ret.close();
conn.commit();
return null;
} else {
Patient pa = new Patient(ret.getString(2), ret.getString(3), ret
.getString(4), ret.getString(5), ret.getString(6), ret
.getString(7), ret.getString(8), ret.getString(9));
pa.setPatientId((new Integer(ret.getInt(1))).toString());
ret.close();
conn.commit();
return pa;
}
}
public ArrayList getDrugPatient(String patientid) throws SQLException {
ArrayList al = new ArrayList();
ResultSet ret;
ret = stmt
.executeQuery("select * from object,drug,medication where medication.patientid = '"
+ patientid
+ "' and medication.objectid = object.objectid and object.objectid = drug.drugnum");
while (ret.next()) {
DrugToPatient dp = new DrugToPatient(ret.getString(2), ret
.getString(3), ret.getInt(4), ret.getFloat(5), ret
.getInt(6), ret.getString(8), ret.getString(9), ret
.getString(10), ret.getString(12), ret.getString(13));
dp.setObjectId((new Integer(ret.getInt(1))).toString());
}
ret.close();
conn.commit();
return al;
}
public ArrayList getRelatives(String patientId) throws SQLException {
ResultSet ret = stmt
.executeQuery("select * from next_of_kin where patientid='"
+ patientId + "'");
ArrayList al = new ArrayList();
while (ret.next()) {
al.add(new Relatives(ret.getString(1), (new Integer(ret.getInt(2)))
.toString(), ret.getString(3), ret.getString(4), ret
.getString(5)));
}
ret.close();
conn.commit();
return al;
}
public Clinic getClinic(String clinicNum) throws SQLException {
ResultSet ret = stmt
.executeQuery("select * from local_doctor where clinicNum='"
+ clinicNum + "'");
if (ret.next()) {
return new Clinic(ret.getString(1), ret.getString(2), ret
.getString(3), ret.getString(4), ret.getString(5));
} else {
return null;
}
}
public ArrayList findPatientInWard(String wardNum) throws SQLException {
ResultSet ret = stmt
.executeQuery("Select * from patient,in_patient where in_patient.wardid = '"
+ wardNum
+ "' and patient.patientId = in_patient.patientId");
ArrayList al = new ArrayList();
while (ret.next()) {
InPatient inpatient = new InPatient(ret.getString(2), ret.getString(3), ret
.getString(4), ret.getString(5), ret.getString(6), ret
.getString(7), ret.getString(8), ret.getString(9), ret
.getString(11), ret.getString(12), ret.getInt(13), ret
.getString(14), ret.getString(15), ret.getString(16), ret
.getString(17));
inpatient.setPatientId((new Integer(ret.getInt(1))).toString());
al.add(inpatient);
}
conn.commit();
ret.close();
return al;
}
public ArrayList getWaitPatients(String wardNum) throws SQLException {
if (wardNum.equals("000"))
return null;
ResultSet ret = stmt
.executeQuery("select * from patient,in_patient where patient.patientId = in_patient.patientId AND in_patient.wardid = '"
+ wardNum + "'and in_date is null");
ArrayList al = new ArrayList();
if (ret.next()) {
InPatient inpatient = new InPatient(ret.getString(2), ret
.getString(3), ret.getString(4), ret.getString(5), ret
.getString(6), ret.getString(7), ret.getString(8), ret
.getString(9), ret.getString(10), ret.getString(12),
Integer.parseInt(ret.getString(11)), ret.getString(13), ret
.getString(14), ret.getString(15), ret
.getString(16));
inpatient.setPatientId(ret.getString(1));
al.add(inpatient);
}
conn.commit();
ret.close();
return al;
}
// **********关于供应商
public ArrayList getSupplier() throws Exception {
ArrayList ret = new ArrayList();
Statement stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery("SELECT* FROM Suppiler");
while (rst.next()) {
ret.add(new Supplier(rst.getString(1), rst.getString(1), rst
.getString(2), rst.getString(3), rst.getString(4)));
}
rst.close();
conn.commit();
return ret;
}
public Supplier getSupplier(String supplierId) throws Exception {
Statement stmt = conn.createStatement();
ResultSet rst = stmt
.executeQuery("SELECT* FROM Suppiler where supplierId='"
+ supplierId + "'");
if (rst.next()) {
Supplier su = new Supplier(rst.getString(1), rst.getString(1), rst
.getString(2), rst.getString(3), rst.getString(4));
rst.close();
conn.commit();
return su;
}
rst.close();
conn.commit();
return null;
}
public boolean addSupplier(Supplier supplier) throws SQLException {
Statement stmt;
try {
stmt = conn.createStatement();
stmt.execute("INSERT INTO Suppiler VALUES('"
+ supplier.getSupplierid() + "','" + supplier.getName()
+ "','" + supplier.getAddress() + "','"
+ supplier.getTele() + "','" + supplier.getFax() + "')");
stmt.close();
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
conn.rollback();
return false;
}
conn.commit();
return true;
}
public boolean deleteSupplier(String supplierid) throws SQLException {
Statement stmt;
try {
stmt = conn.createStatement();
stmt.execute("DELETE FROM Suppiler WHERE supplierid = '"
+ supplierid + "'");
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
conn.rollback();
return false;
}
conn.commit();
return true;
}
public boolean editSupplier(String supplierid, Supplier supplier)
throws SQLException {
Statement stmt;
try {
stmt = conn.createStatement();
stmt.execute("UPDATE Suppiler SET " + "name ='"
+ supplier.getName() + "',address ='"
+ supplier.getAddress() + "',tele ='" + supplier.getTele()
+ "',fax ='" + supplier.getFax() + "'");
stmt.close();
} catch (SQLException e) {
conn.rollback();
return false;
}
conn.commit();
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -