billdao.java

来自「模拟网上购物系统」· Java 代码 · 共 263 行

JAVA
263
字号
package dao;

import java.sql.*;
import java.util.ArrayList;

import po.*;

import vo.*;

public class BillDAO {
	private Connection conn = null;

	private Statement state = null;

	private ResultSet rs = null;

	// 输入收花人信息
	public boolean addreceiveBill(billVO bvo) {
		boolean isok = false;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			int i = state.executeUpdate("insert into receive values("
					+ bvo.getProid() + ",'" + bvo.getSname() + "','"
					+ bvo.getSaddress() + "','" + bvo.getSyear() + "','"
					+ bvo.getSmonth() + "','" + bvo.getSday() + "','"
					+ bvo.getShour() + "','" + bvo.getSfen() + "',"
					+ bvo.getSphone() + ",'" + bvo.getSemail() + "',"
					+ bvo.getSzip() + ",'" + bvo.getProvince() + "','"
					+ bvo.getCity() + "','" + bvo.getTwoclass() + "','"
					+ bvo.getSliuyan() + "','" + bvo.getNiming() + "','"
					+ bvo.getTeshuyaoqiu() + "')");
			if (i > 0) {
				isok = true;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (state != null)
					state.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return isok;
	}

	// 输入订花人信息
	public boolean addscheduleBill(billVO bvo) {
		boolean isok = false;
		System.out.println(bvo.getDaddres());
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			int i = state.executeUpdate("insert into schedule values("
					+ bvo.getProid() + ",'" + bvo.getDname() + "','"
					+ bvo.getDemail() + "'," + bvo.getDtel() + ","
					+ bvo.getDzip() + ",'" + bvo.getDaddres() + "')");
			if (i > 0) 
			{
				isok = true;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (state != null)
				state.close();
				if (conn != null)
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return isok;
	}
	
	//输入购买的物品信息
	public boolean addshopBill(shopVO spo)
	{
		
		boolean isok = false;
		conn = Tools.getConnection();
		try {
			state = conn.createStatement();
			int i = state.executeUpdate("insert into bill values("+spo.getProid()+",'"+spo.getPicture()+"','"+spo.getProname()+"',"+spo.getPrice()+","+spo.getMemberprice()+","+spo.getNum()+")");
		    if(i > 0)
		    {
		    	isok = true;
		    }
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    finally {
		try {
			if (state != null)
			state.close();
			if (conn != null)
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
		return isok;
	}
	
	//根据商品的ID查询记录
	public shopbillPO findByID(shopbillPO spo)
	{
		shopbillPO po = null;
		conn = Tools.getConnection();
		try {
			state = conn.createStatement();
			rs = state.executeQuery("select * from bill where proid = " + spo.getProid());
			if(rs.next())
			{
				po = new shopbillPO();
				po.setProid(rs.getInt("proid"));
				po.setPicture(rs.getString("picture"));
				po.setProname(rs.getString("proname"));
				po.setPrice(rs.getInt("price"));
				po.setMemberprice(rs.getInt("memberprice"));
				po.setNum(rs.getInt("num"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				if(rs != null)
					rs.close();
				if (state != null)
					state.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return po;
	}
	
	//
	public int NextID()
	{
		int id = 0;
		conn = Tools.getConnection();
		try {
			state = conn.createStatement();
			rs = state.executeQuery("select max(proid) max from receive");
			if(rs.next())
			{
				id = rs.getInt("max");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				if(rs != null)
					rs.close();
				if (state != null)
					state.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return id;
	}
	
//	根据商品名查询
	public ArrayList findAll(int pageSize,int startRows,String sql)
	{
		ArrayList array = new ArrayList();
		productPO po = null;
		try {
			conn = Tools.getConnection();
			state = conn.createStatement(
					ResultSet.TYPE_SCROLL_INSENSITIVE,
					ResultSet.CONCUR_READ_ONLY
					);
			rs = state.executeQuery(sql);
			
            rs.absolute(startRows);
			
			for(int i=0;i<pageSize;i++)
			{
				po = new productPO();
				po.setProid(rs.getInt("proid"));
				po.setProname(rs.getString("proname"));
				po.setProprice(rs.getInt("proprice"));
				po.setMemberprice(rs.getInt("memberprice"));
				po.setPicture(rs.getString("picture"));

				array.add(po);
				if(!rs.next())
					break;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (state != null)
				state.close();
				if (conn != null)
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return array;
	}
	
//	查询全部行数
	public int count(String sql)
	{
		int ct = 0;
		
		try {
			conn = Tools.getConnection();
			state = conn.createStatement();
			rs = state.executeQuery(sql);
			if(rs.next())
			{
				ct = rs.getShort("count");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally
		{
			try {
				rs.close();
				state.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return ct;
	}
}

⌨️ 快捷键说明

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