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

📄 sellshoppingtreat.java

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

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

import com.jxc.vo.Sellshopping;
import com.jxc.vo.Shopping;
import com.jxc.vo.Vo;

public class SellshoppingTreat implements Dao {

	public boolean deleteById(Connection conn, int id) {
		// TODO Auto-generated method stub
		boolean flat = false;
		PreparedStatement pstm = null;
		int rs = 0;
		String sql = "delete from sellshopping where id=?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setInt(1, id);
			rs = pstm.executeUpdate();
			if (rs != 0)
				flat = true;
			else
				flat = false;

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (pstm != null)
					pstm.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		return flat;
	}

	public boolean insert(Connection conn, Vo vo) {
		// TODO Auto-generated method stub
		boolean flat = false;
		Sellshopping sesh = (Sellshopping) vo;
		PreparedStatement pstm = null;
		int rs = 0;
		String sql = "insert into sellshopping(sid,outprince,outnum,outtime,yid)values(?,?,?,?,?)";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, sesh.getSid());
			pstm.setInt(2, sesh.getOutprince());
			pstm.setInt(3, sesh.getOutnum());
			pstm.setDate(4, (Date) sesh.getOuttime());
			pstm.setString(5, sesh.getYid());
			rs = pstm.executeUpdate();
			if (rs != 0)
				flat = true;
			else
				flat = false;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (pstm != null)
					pstm.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		return flat;
	}

	public ArrayList<Sellshopping> selectAll(Connection conn) {
		// TODO Auto-generated method stub
		ArrayList<Sellshopping> list = new ArrayList<Sellshopping>();
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select id,sid,outprince,outnum,outtime,yid from sellshopping";
		try {
			pstm = conn.prepareStatement(sql);
			rs = pstm.executeQuery();
			while (rs.next()) {
				Sellshopping sesh = new Sellshopping();
				sesh.setId(rs.getInt(1));
				sesh.setSid(rs.getString(2));
				sesh.setOutprince(rs.getInt(3));
				sesh.setOutnum(rs.getInt(4));
				sesh.setOuttime(rs.getDate(5));
				sesh.setYid(rs.getString(6));
				list.add(sesh);
			}
		} 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 list;
	}

	public boolean updateById(Connection conn, int id, Vo vo) {
		// TODO Auto-generated method stub
		Sellshopping sesh = (Sellshopping) vo;
		boolean flat = false;
		PreparedStatement pstm = null;
		int rs = 0;
		String sql = "update sellshopping set sid=?,outprince=?,outnum=?,outtime=?,yid=? where id=?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setString(1, sesh.getSid());
			pstm.setInt(2, sesh.getOutprince());
			pstm.setInt(3, sesh.getOutnum());
			pstm.setDate(4, (Date) sesh.getOuttime());
			pstm.setString(5, sesh.getYid());
			pstm.setInt(6, id);
			rs = pstm.executeUpdate();
			if (rs != 0)
				flat = true;
			else
				flat = false;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (pstm != null)
					pstm.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return flat;
	}

	public ArrayList selectByTime(Connection conn, Date d1, Date d2) {
		ArrayList<Sellshopping> list = new ArrayList<Sellshopping>();
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select id,sid,outprince,outnum,outtime,yid from sellshopping where outtime>=? and outtime<=?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setDate(1, d1);
			pstm.setDate(2, d2);
			rs = pstm.executeQuery();
			while (rs.next()) {
				Sellshopping sesh = new Sellshopping();
				sesh.setId(rs.getInt(1));
				sesh.setSid(rs.getString(2));
				sesh.setOutprince(rs.getInt(3));
				sesh.setOutnum(rs.getInt(4));
				sesh.setOuttime(rs.getDate(5));
				sesh.setYid(rs.getString(6));
				list.add(sesh);

			}
		} 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 list;
	}

	public ArrayList selectById(Connection conn, String id, Date d1, Date d2) {
		ArrayList<Sellshopping> list = new ArrayList<Sellshopping>();
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select id,sid,outprince,outnum,outtime,yid from sellshopping where outtime>=? and outtime<=? and yid=?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setDate(1, d1);
			pstm.setDate(2, d2);
			pstm.setString(3, id);
			rs = pstm.executeQuery();
			while (rs.next()) {
				Sellshopping sesh = new Sellshopping();
				sesh.setId(rs.getInt(1));
				sesh.setSid(rs.getString(2));
				sesh.setOutprince(rs.getInt(3));
				sesh.setOutnum(rs.getInt(4));
				sesh.setOuttime(rs.getDate(5));
				sesh.setYid(rs.getString(6));
				list.add(sesh);

			}
		} 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 list;
	}

	public ArrayList selectBySid(Connection conn, String id, Date d1, Date d2) {
		ArrayList<Sellshopping> list = new ArrayList<Sellshopping>();
		PreparedStatement pstm = null;
		ResultSet rs = null;
		String sql = "select id,sid,outprince,outnum,outtime,yid from sellshopping where outtime>=? and outtime<=? and sid=?";
		try {
			pstm = conn.prepareStatement(sql);
			pstm.setDate(1, d1);
			pstm.setDate(2, d2);
			pstm.setString(3, id);
			rs = pstm.executeQuery();
			while (rs.next()) {
				Sellshopping sesh = new Sellshopping();
				sesh.setId(rs.getInt(1));
				sesh.setSid(rs.getString(2));
				sesh.setOutprince(rs.getInt(3));
				sesh.setOutnum(rs.getInt(4));
				sesh.setOuttime(rs.getDate(5));
				sesh.setYid(rs.getString(6));
				list.add(sesh);

			}
		} 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 list;
	}
	
	public Vo selectById(Connection conn, int id){
		Sellshopping vo=new Sellshopping();
		PreparedStatement pstm=null;
		ResultSet rs=null;
		String sql="select id,sid,outprince,outnum,outtime,yid from sellshopping where id=?";
		try {
			pstm=conn.prepareStatement(sql);
			pstm.setInt(1, id);
			rs=pstm.executeQuery();
			if(rs.next()){
				vo.setId(rs.getInt(1));
				vo.setSid(rs.getString(2));
				vo.setOutprince(rs.getInt(3));
				vo.setOutnum(rs.getInt(4));
				vo.setOuttime(rs.getDate(5));
				vo.setYid(rs.getString(6));
			}
		} 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 vo;
	}

	
}

⌨️ 快捷键说明

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