fundapplydao.java

来自「仓库管理系统,适合各种行业的仓库管理系统」· Java 代码 · 共 153 行

JAVA
153
字号
package com.bean.DAO;

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

import com.bean.DTO.AppbuyDTO;
import com.bean.DTO.FundapplyDTO;

public class FundapplyDAO {
	private Connection con;
	private List<FundapplyDTO> list = new ArrayList<FundapplyDTO>();
	private PreparedStatement ps;

	public FundapplyDAO(Connection con) {
		this.con = con;
	}

	public List<FundapplyDTO> getAll(int curpage) {
		list.clear();
		try {
			ps = con.prepareStatement("select * from fundapply",
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY);
			ResultSet rs = ps.executeQuery();
			rs.absolute((curpage - 1) * 5 + 1);
			rs.previous();
			int counter = 0;
			while (rs.next() && counter < 5) {
				FundapplyDTO pd = new FundapplyDTO();
				pd.setApplyID(rs.getInt(1));
				pd.setFund(rs.getFloat(2));
				pd.setReason(rs.getString(3));
				pd.setApplytime(rs.getString(4));
				pd.setStateID(rs.getInt(5));
				list.add(pd);
				counter++;
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	public int getTotalPage() {
		int totalpage = 1;
		try {
			ps = con.prepareStatement("select count(*) from fundapply");
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				totalpage = (rs.getInt(1) + 4) / 5;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return totalpage;
	}

	public void update(int applyID) {
		try {
			ps = con
					.prepareStatement("update fundapply set stateID=6 where applyID=?");
			ps.setInt(1, applyID);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void update1(int applyID) {
		try {
			ps = con
					.prepareStatement("update fundapply set stateID=5 where applyID=?");
			ps.setInt(1, applyID);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void del(int applyID) {
		try {
			ps = con.prepareStatement("delete from fundapply  where applyID=?");
			ps.setInt(1, applyID);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public void add(FundapplyDTO dto) {
		try {
			ps = con.prepareStatement("insert into fundapply values(?,?,?,?)");
			ps.setFloat(1, dto.getFund());
			ps.setString(2, dto.getReason());
			ps.setString(3, dto.getApplytime());
			ps.setInt(4, 0);
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public FundapplyDTO getByID(int applyID) {
		FundapplyDTO dto = new FundapplyDTO();
		try {
			ps = con
					.prepareStatement("select * from fundapply where applyID=?");
			ps.setInt(1, applyID);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				dto.setApplyID(rs.getInt(1));
				dto.setFund(rs.getFloat(2));
				dto.setReason(rs.getString(3));
				dto.setApplytime(rs.getString(4));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dto;
	}

	public void update2(FundapplyDTO dto) {
		try {
			ps = con.prepareStatement("update fundapply set fund=?,reason=?,applytime=? where applyID=?");
			ps.setFloat(1, dto.getFund());
			ps.setString(2, dto.getReason());
			ps.setString(3, dto.getApplytime());
			ps.setInt(4, dto.getApplyID());
			ps.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}

⌨️ 快捷键说明

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