⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentdao.java

📁 学生成绩课程管理系统 看看
💻 JAVA
字号:
package com.accp;

import java.sql.*;
import java.util.ArrayList;

public class StudentDAO {
	
	public ArrayList getStu(StudentVO stu) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		ArrayList stuList = new ArrayList();

		String sql = "select * from stu_info where stuId like ? and stuName like ?";
		conn = DBConnect.getConnection();
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, "%" + stu.getStuId() + "%");
			pst.setString(2, "%" + stu.getStuName() + "%");
			rs = pst.executeQuery();
			while (rs.next()) {
				StudentVO rsVO = new StudentVO();
				rsVO.setStuId(rs.getString(1).trim());
				rsVO.setStuName(rs.getString(2).trim());
				rsVO.setStuAge(rs.getInt(3));
				rsVO.setStuAddress(rs.getString(4).trim());
				stuList.add(rsVO);
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally{
			DBConnect.closeResult(rs);
			DBConnect.closePreparedStatement(pst);
			DBConnect.closeConnection(conn);
		}
		return stuList;
	}
//查询信息,将信息置给控件吧
	public StudentVO disStu(StudentVO stu) {
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		StudentVO rsVO = null;
		String sql = "select * from stu_info where stuId =?";
		conn = DBConnect.getConnection();
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1, stu.getStuId());
			rs = pst.executeQuery();
			while (rs.next()) {
				rsVO = new StudentVO();
				rsVO.setStuId(rs.getString(1).trim());
				rsVO.setStuName(rs.getString(2).trim());
				rsVO.setStuAge(rs.getInt(3));
				rsVO.setStuAddress(rs.getString(4).trim());
			}
			return rsVO;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}finally{
			DBConnect.closeResult(rs);
			DBConnect.closePreparedStatement(pst);
			DBConnect.closeConnection(conn);
		}

	}
//修改信息
	public boolean updateStu(StudentVO stu){
		boolean sucess = false;
		int count = 0;
		
		Connection conn = null;
		PreparedStatement pst = null;
		String sql = "update stu_info set stuName=?,stuAge=?,stuAddress=? where stuId=?";
		
		conn = DBConnect.getConnection();
		try {
			pst = conn.prepareStatement(sql);
			pst.setString(1,stu.getStuName());
			pst.setInt(2,stu.getStuAge());
			pst.setString(3,stu.getStuAddress());
			pst.setString(4,stu.getStuId());
			count = pst.executeUpdate();
			if(count!=0){
				sucess = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBConnect.closePreparedStatement(pst);
			DBConnect.closeConnection(conn);
		}
		
		return sucess;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -