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

📄 studentdao.java

📁 用Java语言实现学生信息管理系统 对此感兴趣的同学去浏览
💻 JAVA
字号:
package com.yourcompany.struts.service;

import com.yourcompany.struts.common.DBTools;
import com.yourcompany.struts.common.Pool;
import com.yourcompany.struts.vo.Student;
import java.sql.*;
import java.util.ArrayList;

public class StudentDAO {
	Pool p = new Pool();

	public boolean login(Student stu) {
		String sql = "select * from Student where sname='" + stu.getSname()
				+ "' and pwd='" + stu.getPwd() + "'";
		Connection con = p.getPoolConnection();
		Statement sta = null;
		ResultSet rs = null;
		try {
			sta = con.createStatement();
			rs = sta.executeQuery(sql);
			if (rs.next()) {
				return true;
			}

		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
			return false;
		} finally {
			try {
				rs.close();
				sta.close();
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}

		}

		return false;
	}

	public ArrayList queryAll() {
		String sql = "select * from Student";
		Connection con = p.getPoolConnection();
		Statement sta = null;
		ResultSet rs = null;
		ArrayList list = new ArrayList();
		try {
			sta = con.createStatement();
			rs = sta.executeQuery(sql);
			Student stu = null;
			while (rs.next()) {
				stu = new Student();
				stu.setSid(rs.getInt(1));
				stu.setSname(rs.getString(2));
				stu.setAge(rs.getInt(3));
				stu.setPwd(rs.getString(4));
				list.add(stu);
			}

		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				sta.close();
				con.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}

		}
		return list;
	}
	
	public int delStu(Student stu){
		DBTools tool = new DBTools();
		String sql = "delete from student where sid = "+stu.getSid();
		return tool.executeUpdate(sql);
	}
	
}














⌨️ 快捷键说明

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