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

📄 studentdao.java

📁 学生信息管理系统
💻 JAVA
字号:
package dao;
import java.sql.*;
import conn.ConnectDB;
import java.util.*;
import vo.*;
public class StudentDAO 
{
	public StudentDAO()
	{
	}
	public boolean checkStudent(String student_id)
	{
		ResultSet rs=null;
		boolean isexist=false;
		try
		{
			String sql="select * from student where student_id='"+student_id+"'";
			Connection conn=ConnectDB.getConnection();
			Statement stat=conn.createStatement();
			rs=stat.executeQuery(sql);
			if(rs.next())
			{
				isexist=true;
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return isexist;
	}
	public StudentVO getStudentById(String student_id)
	{
		StudentVO studentvo=null;
		ResultSet rs=null;
		try
		{
			studentvo=new StudentVO();
			Connection conn=ConnectDB.getConnection();
			Statement stat=conn.createStatement();
			rs=stat.executeQuery("select * from student where student_id='"+student_id+"'");
			if(rs.next())
			{
				studentvo.setStudentId(rs.getString("student_id"));
				studentvo.setStudentName(rs.getString("name"));
				studentvo.setSex(rs.getString("sex"));
				studentvo.setClassId(rs.getString("class_id"));
				studentvo.setBirthday(rs.getString("birth_date"));
				studentvo.setAddress(rs.getString("address"));
			}
			rs=stat.executeQuery("select * from studentphone where student_id='"+student_id+"'");
			if(rs.next())
			{
				studentvo.setPhone(rs.getString("telephone"));
				
			}
			rs=stat.executeQuery("select * from studentemail where student_id='"+student_id+"'");
			if(rs.next())
			{
				studentvo.setPhone(rs.getString("email"));
				
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return studentvo;
	}
	public ArrayList getStudentByName(String student_name)
	{
		StudentVO studentvo=null;
		ArrayList students=null;
		ResultSet rs=null;
		try
		{
			students=new ArrayList();
			Connection conn=ConnectDB.getConnection();
			Statement stat=conn.createStatement();
			rs=stat.executeQuery("select * from student where student_name='"+student_name+"'");
			while(rs.next())
			{
				studentvo=new StudentVO();
				studentvo.setStudentId(rs.getString("student_id"));
				studentvo.setStudentName(rs.getString("name"));
				studentvo.setSex(rs.getString("sex"));
				studentvo.setBirthday(rs.getString("birth_date"));
			//	studentvo.setPhone(rs.getString("telephone"));
				studentvo.setClassId(rs.getString("class_id"));
				studentvo.setAddress(rs.getString("address"));
			//	studentvo.setEmail(rs.getString("email"));
				students.add(studentvo);	
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return students;
		
		
	}
	public ArrayList getStudents()
	{
		ArrayList students=null;
		try
		{
			students=new ArrayList();
			Connection conn=ConnectDB.getConnection();
			Statement stat=conn.createStatement();
			ResultSet rs=stat.executeQuery("select * from student ,studentphone,studentemail ");
			if(rs.next())
			{
				StudentVO studentvo=new StudentVO();
				studentvo.setStudentId(rs.getString("student_id"));
				studentvo.setStudentName(rs.getString("name"));
				studentvo.setSex(rs.getString("sex"));
				studentvo.setClassId(rs.getString("class_id"));
				studentvo.setBirthday(rs.getString("birth_date"));
				studentvo.setAddress(rs.getString("address"));
				studentvo.setPhone(rs.getString("telephone"));
				studentvo.setEmail(rs.getString("email"));
				students.add(studentvo);
			}
			
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		return students;
	}
	public void insertStudent(StudentVO studentvo)
	{
		try
		{
			ConnectDB.executeUpdate("insert into student values('"+studentvo.getStudentId()+"','"+studentvo.getStudentName()+"','"+studentvo.getSex()+"','"+studentvo.getClassId()+"','"+studentvo.getBirthday()+"','"+studentvo.getAddress()+"')");
			ConnectDB.executeUpdate("insert into studentemail (student_id,email) values('"+studentvo.getStudentId()+"','"+studentvo.getEmail()+"')");
			ConnectDB.executeUpdate("insert into studentphone (student_id,telephone) values('"+studentvo.getStudentId()+"','"+studentvo.getPhone()+"')");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	public void updateStudent(StudentVO studentvo)
	{
		ResultSet rs=null;
   		
   		try
   		{
   			String sql="select * from student where student_id='"+studentvo.getStudentId()+"'";
   			Connection conn=ConnectDB.getConnection();
   			Statement stat=conn.createStatement();
   			rs=stat.executeQuery(sql);
   			if(rs.next())
   			{
   				ConnectDB.executeUpdate("update student set name='"+studentvo.getStudentName()+"',sex='"+studentvo.getSex()+"',class_id='"+studentvo.getClassId()+"',birth_date='"+studentvo.getBirthday()+"',address='"+studentvo.getAddress()+"'where student_id='"+studentvo.getStudentId()+"'");
   				ConnectDB.executeUpdate("update studentemail set email='"+studentvo.getEmail()+"'where student_id='"+studentvo.getStudentId()+"'");
   				ConnectDB.executeUpdate("update studentphone set telephone='"+studentvo.getPhone()+"'where student_id='"+studentvo.getStudentId()+"'");
   			}
   			
   			
   		}
   		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	public void deleteStudent(String student_id)
	{
		ResultSet rs=null;
   		try
   		{
   			Connection conn=ConnectDB.getConnection();
   			Statement stat=conn.createStatement();
   			rs=stat.executeQuery("select * from student where student_id='"+student_id+"'");
   			if(rs.next())
   			{
   				ConnectDB.executeUpdate("delete from studentphone where student_id='"+student_id+"'");
   				ConnectDB.executeUpdate("delete from studentemail where student_id='"+student_id+"'");
   				ConnectDB.executeUpdate("delete from student   where student_id='"+student_id+"'");
   			}
   		}
   		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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