首页>代码>基于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;
		}
	}
}
最近下载更多
WenMeng  LV9 2024年12月2日
PISCESPLUS  LV5 2024年9月3日
仙女山的月亮  LV2 2024年5月22日
微信网友_6790506018131968  LV1 2024年1月3日
asddwh  LV13 2023年12月26日
17693282606  LV12 2023年12月20日
李朝磊  LV18 2023年12月7日
qiangmin1223  LV12 2023年4月24日
wwfl02  LV3 2022年12月5日
485415187  LV6 2022年11月20日
最近浏览更多
新哥新奇士橙  LV5 1月26日
WenMeng  LV9 2024年12月2日
PISCESPLUS  LV5 2024年9月3日
xiao小果  LV13 2024年8月24日
柳咪华沙  LV7 2024年6月29日
范德萨发顺丰的  LV1 2024年6月16日
123momom 2024年6月9日
暂无贡献等级
123456cjj  LV1 2024年6月2日
仙女山的月亮  LV2 2024年5月22日
op123129 2024年4月15日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友