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

📄 persontreat.java

📁 是一个企业的进销存系统。账号问1001密码为123456
💻 JAVA
字号:
package com.jxc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import com.jxc.vo.Person;
import com.jxc.vo.Vo;

public class PersonTreat implements Dao {
	
	public boolean login(Connection conn,String yid,String pwd ,String job){
		boolean flat=true;
		PreparedStatement pstm=null;
		ResultSet rs=null;
		String sql="select * from person where yid=? and ypwd=? and yjob=?";
		try {
			pstm=conn.prepareStatement(sql);
			pstm.setString(1, yid);
			pstm.setString(2, pwd);
			pstm.setString(3, job);
			rs=pstm.executeQuery();
			if(rs.next()){
				flat=true;
			}else{
				flat=false;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				if(rs!=null)
					rs.close();
				if(pstm!=null)
					pstm.close();
				if(conn!=null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return flat;
	}

	public boolean deleteById(Connection conn, String yid) {

		boolean bb = false;
		int rs = 0;
		Statement ee = null;
		try {
			ee = conn.createStatement();
			rs = ee.executeUpdate("delete from person where yid='"
					+ yid + "'");
			if (rs != 0) {
				bb = true;
			} else {
				bb = false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			if(ee!=null){
				try {
					ee.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return bb;
	}

	public boolean insert(Connection conn, Vo vo) {
		// TODO Auto-generated method stub
	        Statement ee=null;
	        Person person=(Person)vo;
	        int sr=0;
	        boolean i=false;
		try {
			ee = conn.createStatement();
			sr=ee.executeUpdate("insert into person(yid,yname,ysex,ypho,yjob,yaddr,yage)values('"+person.getYid()+"','"+person.getYname()+"','"+person.getYsex()+"','"+person.getYpho()+"','"+person.getYjob()+"','"+person.getYaddr()+"',"+person.getYage()+")");
		  if(sr!=0){
			  i=true;
		  }else{
			  i=false;
		  }
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			if(ee!=null){
				try {
					ee.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(conn!=null){
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return i;
	}

	public ArrayList<Person> selectAll(Connection conn) {
		// TODO Auto-generated method stub
		ArrayList<Person> array=new ArrayList<Person>();
		Statement ee=null;
		ResultSet rs=null;
		try {
			ee = conn.createStatement();
			rs = ee.executeQuery("select yid,yname,ysex,yage,yjob,ypho,yaddr from person");
			while (rs.next()) {
				Person person=new Person();
				person.setYid(rs.getString (1));
				person.setYname(rs.getString(2));
				person.setYsex(rs.getString(3));
				person.setYage(rs.getShort(4));
				person.setYjob(rs.getString(5));
				person.setYpho(rs.getString(6));
				person.setYaddr(rs.getString(7));
				array.add(person);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try{
				if(rs!=null){
					rs.close();
				}
				if(ee!=null){
					ee.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return array;
	}

	public Vo selectById(Connection conn, String yid) {
		// TODO Auto-generated method stub
		Statement ee=null;
		ResultSet rs=null;
		Person person=new Person();
		try {
			ee = conn.createStatement();
			rs = ee.executeQuery("select * from person where yid='"+yid+"'");
			while (rs.next()) {
				person.setYid(rs.getString(1));
				person.setYpwd(rs.getString(2));
				person.setYname(rs.getString(3));
				person.setYsex(rs.getString(4));
				person.setYpho(rs.getString(5));
				person.setYjob(rs.getString(6));
				person.setYaddr(rs.getString(7));
				person.setYage(rs.getShort(8));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try{
				if(rs!=null){
					rs.close();
				}
				if(ee!=null){
					ee.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return person;
	}

	public boolean selectId(Connection conn, String yid) {
		// TODO Auto-generated method stub
		boolean flat=false;
		Statement ee=null;
		ResultSet rs=null;
		try {
			ee = conn.createStatement();
			rs = ee.executeQuery("select * from person where yid='"+yid+"'");
			while (rs.next()) {
			flat=true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try{
				if(rs!=null){
					rs.close();
				}
				if(ee!=null){
					ee.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return flat;
	}
	
	public boolean updateById(Connection conn, String yid, Vo vo) {
		// TODO Auto-generated method stub
		Person person=(Person)vo;
		boolean i=false;
		PreparedStatement ee=null;
		int rs=0;
		String sql="update person set yid=?,yname=?,ysex=?,yjob=?,yage=?,ypho=?,yaddr=? where yid=?";
		try{
			ee = conn.prepareStatement(sql);
			ee.setString(1, person.getYid());
			ee.setString(2, person.getYname());
			ee.setString(3, person.getYsex());
			ee.setString(4, person.getYjob());
			ee.setShort(5, person.getYage());
			ee.setString(6, person.getYpho());
			ee.setString(7, person.getYaddr());
			ee.setString(8,yid);
			rs=ee.executeUpdate();
		if(rs!=0){
			i=true;
		}else{
			i=false;
		}
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			try{
				if(ee!=null){
					ee.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return i;
	}
    
	public boolean chagePwd(Connection conn,String yid,String ypwd){
		 PreparedStatement ee=null;
		 int sr=0;
		 boolean b=false;
		 //Person person=new Person();
		 String sql="update person set ypwd=? where yid=?";
		 try{
			 ee=conn.prepareStatement(sql);
			 ee.setString(1, ypwd);
			 ee.setString(2, yid);
			 sr=ee.executeUpdate();
			 if(sr!=0){
				 b=true;
			 }else{
				 b=false;
			 }
			} catch (SQLException e) {
				e.printStackTrace();
			}
			finally{
				try{
					if(ee!=null){
						ee.close();
					}
					if(conn!=null){
						conn.close();
					}
				}catch(SQLException e){
					e.printStackTrace();
				}
			}
			return b;
}
	    
	public ArrayList<Person> selectByJop(Connection conn,String jop){
		ArrayList<Person> array=new ArrayList<Person>();
		Statement ee=null;
		ResultSet rs=null;
		try{
			ee=conn.createStatement();
			rs=ee.executeQuery("select * from person where yjob='"+jop+"'");
			while (rs.next()) {
				Person person=new Person();
				person.setYid(rs.getString(1));
				person.setYpwd(rs.getString(2));
				person.setYname(rs.getString(3));
				person.setYsex(rs.getString(4));
				person.setYpho(rs.getString(5));
				person.setYjob(rs.getString(6));
				person.setYaddr(rs.getString(7));
				person.setYage(rs.getShort(8));
				array.add(person);
			}	
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			try{
				if(rs!=null){
					rs.close();
				}
				if(ee!=null){
					ee.close();
				}
				if(conn!=null){
					conn.close();
				}
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return array;
}


	
}

⌨️ 快捷键说明

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