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

📄 depotoperate.java

📁 Athena酒店小组_Athena酒店管理系统
💻 JAVA
字号:
/*
 * DepotOperate.java
 *
 * Created on 2007年6月4日, 上午1:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jack;
import java.sql.*;
import java.util.*;
import plugin.*;
import helper.*;

/**
 *实现Depot的操作类
 * @author zzx
 */
public class DepotOperate {
    private IDBResource dbRes;
    
    /**
     * 构造函数
     * @param dbRes 数据库资源
     */
    public DepotOperate(IDBResource _dbRes) 
    {
        this.dbRes=_dbRes;
    }
    
    /**
     * 对DepotInfo表进行插入操作
     * @param depotinfo 要插入的信息
     * @return 影响的行数,如果发生错误,则返回-1
     */
    public int insert(DepotInfo depotinfo)
    {
        try
        {
            Connection conn = dbRes.getConnection();
            String sql="INSERT INTO DepotInfo(DepotID,DepotName,Location,Principal,"+
                    "Tel,Remark)"+"VALUES(?,?,?,?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, depotinfo.getDepotID());
            ps.setString(2, depotinfo.getDepotName());
            ps.setString(3, depotinfo.getLocation());
            ps.setString(4, depotinfo.getPrincipal());
            ps.setString(5, depotinfo.geTtel());
            ps.setString(6, depotinfo.getRemark());
            int rs = ps.executeUpdate();
	    return rs;
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
	    return -1;
        }
    }
    
    /**
     * 对DepotInfo表进行更新操作
     * @param depotinfo 要更新的仓库信息
     * @return 影响的行数,如果发生错误,则返回-1
     */
    public int update(DepotInfo depotinfo)
    {
        try
        {
            Connection conn = dbRes.getConnection();
            String sql="UPDATE DepotInfo SET DepotName=?,Location=?,Principal=?,"+
                    "Tel=?,Remark=? WHERE DepotID=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, depotinfo.getDepotName());
            ps.setString(2, depotinfo.getLocation());
            ps.setString(3, depotinfo.getPrincipal());
            ps.setString(4, depotinfo.geTtel());
            ps.setString(5, depotinfo.getRemark());
            ps.setString(6, depotinfo.getDepotID());
            int rs = ps.executeUpdate();
	    return rs;
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
	    return -1;
        }
    }
    
    /**
     * 对DepotInfo表进行删除操作
     * @param depotinfo 要删除的仓库信息
     * @return 影响的行数,如果发生错误,则返回-1
     */
    public int delete(DepotInfo depotinfo)
    {
        try
        {
            Connection conn = dbRes.getConnection();
	    String sql = "DELETE FROM DepotInfo WHERE DepotId = ?";
	    PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, depotinfo.getDepotID());
	    int rs = ps.executeUpdate();
	    return rs;
        }
       catch(SQLException ex)
        {
            ex.printStackTrace();
	    return -1;
        } 
    }
    
    /**
     * 返回DepotInfo表的所有信息
     * @return 所有仓库信息
     */
    public ArrayList<DepotInfo> getAllDepot()
    {
        try
        {
            Connection conn = dbRes.getConnection();
	    String sql = "SELECT * FROM DepotInfo";
            PreparedStatement ps = conn.prepareStatement(sql);
	    ResultSet rs = ps.executeQuery();
	    ArrayList<DepotInfo> depot = new ArrayList<DepotInfo>();
	    readData(depot, rs);
	    return depot;
        }
        catch(SQLException ex)
        {
            ex.printStackTrace();
            return null;
        }
    }
    
    
    /**
     * 根据Id查询DepotInfo表的信息
     * @param _depotId 仓库的ID
     * @return 查询到的仓库信息
     */
    public DepotInfo getDepotByID(String _depotID)
    {
        try{
            Connection conn = dbRes.getConnection();
            String sql="SELECT * FROM DepotInfo WHERE DepotID=?";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setString(1, _depotID);
            ResultSet rs = ps.executeQuery();
            ArrayList<DepotInfo> depot = new ArrayList<DepotInfo>();
            readData(depot, rs);
            if (depot.size() != 1)
	    {
		return null;
	    }
	    return depot.get(0);
        }
        catch (SQLException ex)
	{
		ex.printStackTrace();
		return null;
	}
    }

    
    /**
     * 根据条件查询DepotInfo表的信息
     * @param names 条件的名称
     * @param values 条件的值
     * @return 查询到的仓库信息
     */
    public ArrayList<DepotInfo> getDepotBycondition(String name,String values)
    {
        try
        {
            Connection conn = dbRes.getConnection();
            String sql="SELECT * FROM DepotInfo WHERE "+name+" LIKE'%"+values+"%'";
            PreparedStatement ps = conn.prepareStatement(sql);
            ResultSet rs = ps.executeQuery();
            ArrayList<DepotInfo> depot=new ArrayList<DepotInfo>();
            readData(depot,rs);
            return depot;
        }
        catch (SQLException ex)
	{
		ex.printStackTrace();
		return null;
	}
    }

    
    
    //读取数据
    private void readData(ArrayList<DepotInfo> depot,ResultSet rs) throws SQLException
    {
        while(rs.next())
        {
            DepotInfo di=new DepotInfo();
            di.setDepotID(rs.getString("DepotID"));
            di.setDepotName(rs.getString("DepotName"));
            di.setLocation(rs.getString("Location"));
            di.setPrincipal(rs.getString("Principal"));
            di.setTel(rs.getString("Tel"));
            di.setRemark(rs.getString("Remark"));
            depot.add(di);
        }
    }    
}

⌨️ 快捷键说明

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