package com.yuki.dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import com.yuki.servlet.index;
import com.yuki.staff.*;
public class Staff_Jdbc {
private Connection conn = null;
public PreparedStatement pst = null;
public ResultSet rst = null;
private String sql=null;
private boolean ret=false;
//增删改
public boolean zeng(Staff staff){
sql="insert into tb_staff_info values(null,?,?,?,?)";
ret = Transform(sql, staff.getName(), staff.getGender(), staff.getBirthday(), staff.getPhone());
return ret;
}
public boolean shan(Staff staff){
sql="delete from tb_staff_info where staff_id=?";
ret = Transform(sql, staff.getId());
return ret;
}
public boolean gai(Staff staff){
sql="update tb_staff_info set staff_name=?,staff_sex=?,staff_birthday=?,staff_phone=? where staff_id=?)";
ret = Transform(sql, staff.getName(), staff.getGender(), staff.getBirthday(), staff.getPhone(),staff.getId());
return ret;
}
//变
private boolean Transform(String sql, Object... objects) {
try {
conn = DbConnection.getConn();
pst = conn.prepareStatement(sql);
for (int i = 0; i < objects.length; i++) {
pst.setObject(i + 1, objects[i]);
}
int rows = pst.executeUpdate();
DbConnection.getClose(conn, pst, rst);
return rows > 0;
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
//查
public List<Staff> select() {
List<Staff> StaList=new ArrayList<>();
conn = DbConnection.getConn();
try {
sql="select * from tb_staff_info;";
pst = conn.prepareStatement(sql);
rst = pst.executeQuery();
while(rst.next()) {
Staff staff=new Staff();
staff.setId(rst.getInt("staff_id"));
staff.setName(rst.getString("staff_name"));
staff.setGender(rst.getString("staff_sex"));
staff.setBirthday(rst.getString("staff_birthday"));
staff.setPhone(rst.getString("staff_phone"));
StaList.add(staff);
}
DbConnection.getClose(conn, pst, rst);
} catch (SQLException e) {
e.printStackTrace();
}
return StaList;
}
public Staff find(int id) {
conn = DbConnection.getConn();
Staff staff=new Staff();
try {
sql="select * from tb_staff_info where staff_id="+id;
pst = conn.prepareStatement(sql);
rst = pst.executeQuery();
while(rst.next()) {
staff.setId(id);
staff.setName(rst.getString("staff_name"));
staff.setGender(rst.getString("staff_sex"));
staff.setBirthday(rst.getString("staff_birthday"));
staff.setPhone(rst.getString("staff_phone"));
}
DbConnection.getClose(conn, pst, rst);
} catch (SQLException e) {
e.printStackTrace();
}
return staff;
}
// public static void main(String[] args) {
// Staff sta=new Staff_Jdbc().find(1);
// System.out.println(sta);
//
// }
}
最近下载更多
long123_356 LV8
2024年12月22日
cong58cong LV8
2024年6月26日
今晚都别睡啦 LV9
2024年6月1日
微信网友_6906962132258816 LV7
2024年3月22日
RAINK_L LV3
2023年12月13日
jiemomo LV12
2023年10月19日
微信网友_6672184532766720 LV3
2023年10月10日
诺一啊啊啊啊啊 LV3
2023年6月15日
KAIzx11 LV8
2023年6月13日
gala209 LV3
2023年2月2日
最近浏览更多
jaonsang LV25
7月20日
18028265352 LV1
6月22日
444105047 LV6
1月17日
cxdddd LV1
2024年12月31日
yongle LV1
2024年12月31日
long123_356 LV8
2024年12月22日
120_wu LV4
2024年12月2日
yimaoermao LV1
2024年11月28日
张泽帅 LV6
2024年10月18日
040313 LV1
2024年10月16日

