首页>代码>基于jsp,javaBean,servlet开发的java web教务后台管理系统>/TeacgersManagement/src/com/tcd/service/stuInfoService.java
package com.tcd.service; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.tcd.model.stuInfo; public class stuInfoService { /** * ��֤�û��Ƿ�Ϸ� */ private Connection conn; private PreparedStatement pstmt; public stuInfoService() { conn = new com.tcd.conn.conn().getCon(); } /** * �����ݿ������ѧ����Ϣ * @param stu * @return */ public boolean addStu(stuInfo stu){ try { pstmt =conn.prepareStatement("insert into studentinfo" +"(nicheng,truename,xb,zy,kc,xq,bz)" +"values(?,?,?,?,?,?,?)"); pstmt.setString(1, stu.getNicheng()); pstmt.setString(2, stu.getTruename()); pstmt.setByte(3, stu.getXb()); pstmt.setString(4, stu.getZy()); pstmt.setString(5, stu.getKcs()); pstmt.setString(6, stu.getXqs()); pstmt.setString(7, stu.getBz()); pstmt.executeUpdate(); return true; } catch (SQLException e) { e.printStackTrace(); return false; } } /** * ��ѯѧ����Ϣ * @return */ public List queryAllStu(){ List stus = new ArrayList(); try { pstmt =conn.prepareStatement("select * from studentinfo"); ResultSet rs = pstmt.executeQuery(); while(rs.next()){ stuInfo stu = new stuInfo(); stu.setId(rs.getInt(1)); stu.setNicheng(rs.getString(2)); stu.setTruename(rs.getString(3)); stu.setXb(rs.getByte(4)); stu.setZy(rs.getString(5)); if(rs.getString(6)!=null) stu.setKc(rs.getString(6).split("&")); if(rs.getString(7)!=null) stu.setXq(rs.getString(7).split("&")); stu.setBz(rs.getString(8)); stus.add(stu); } return stus; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return null; } } /** * ����ѧ��id��ѯѧ����Ϣ * @param id * @return */ public stuInfo queryStubyID(int id){ //List stus = new ArrayList(); try { pstmt =conn.prepareStatement("select * from studentinfo where id=?"); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); if(rs.next()){ stuInfo stu = new stuInfo(); stu.setId(rs.getInt(1)); stu.setNicheng(rs.getString(2)); stu.setTruename(rs.getString(3)); stu.setXb(rs.getByte(4)); stu.setZy(rs.getString(5)); if(rs.getString(6)!=null) stu.setKc(rs.getString(6).split("&")); if(rs.getString(7)!=null) stu.setXq(rs.getString(7).split("&")); stu.setBz(rs.getString(8)); //stus.add(stu); return stu; } return null; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return null; } } /** * ��ѧ����Ϣ * @param stu * @return */ public boolean updateStu(stuInfo stu){ try { pstmt = conn.prepareStatement("update studentinfo set nicheng=?,truename=?,xb=?," + "zy=?,kc=?, xq=?,bz=? where id=?"); pstmt.setString(1, stu.getNicheng()); pstmt.setString(2, stu.getTruename()); pstmt.setByte(3, stu.getXb()); pstmt.setString(4, stu.getZy()); pstmt.setString(5, stu.getKcs()); pstmt.setString(6, stu.getXqs()); pstmt.setString(7, stu.getBz()); pstmt.setInt(8, stu.getId()); pstmt.executeUpdate(); return true; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); return false; } } /** * ɾ��ѧ����Ϣ * @param id * @return */ public boolean deleteStu(int id){ try { pstmt = conn.prepareStatement("delete from studentinfo where id=?"); pstmt.setInt(1, id); pstmt.executeUpdate(); return true; } catch (Exception e) { e.getStackTrace(); return false; } } }
最近下载更多
微信网友_6790506018131968 LV1
1月3日
asddwh LV12
2023年12月26日
17693282606 LV11
2023年12月20日
李朝磊 LV18
2023年12月7日
qiangmin1223 LV12
2023年4月24日
wwfl02 LV3
2022年12月5日
485415187 LV6
2022年11月20日
lvhongquan LV11
2022年6月16日
Xuan_0426 LV5
2022年6月7日
3305787467 LV12
2022年5月23日