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

📄 warehouseda.java

📁 医药供应链管理系统
💻 JAVA
字号:
package com.captainli.dboperation;

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.captainli.bean.WarehouseBean;
import com.captainli.struts.form.WarehouseForm;
import com.captainli.util.GetConnection;

/**
 * warehouse数据库操作类
 * @author CaptainLi
 *
 */
public class WarehouseDA {
	private Connection conn = GetConnection.getConn();
	private PreparedStatement pstmt = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	/**
	 * 关闭数据库对象
	 *
	 */
	public void closeDB(){
		try {
			if(rs != null){
				rs.close();
			}
			if(stmt != null){
				stmt.close();
			}
			if(pstmt != null){
				pstmt.close();
			}
			if(conn != null){
				conn.close();
			}
		} catch (Exception e) {
			e.getStackTrace();
		}
	}
	/**
	 * 返回所有的仓库
	 * @return
	 */
	public ArrayList selectWarehouse(){
		ArrayList arry = new ArrayList();
		WarehouseBean bean = null;
		String sql = "select * from warehouse order by w_id";
		try {
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				bean = new WarehouseBean(rs.getInt("w_id"), rs.getString("w_name"), rs.getString("w_tel"), rs.getString("w_note"));
				arry.add(bean);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeDB();
		}
		return arry;
	}
	/**
	 * 通过ID返回仓库信息
	 * @param w_id
	 * @return
	 */
	public WarehouseBean selectWarehouseByID(int w_id){
		WarehouseBean bean = null;
		String sql = "select * from warehouse where w_id = ?";
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, w_id);
			rs = pstmt.executeQuery();
			while(rs.next()){
				bean = new WarehouseBean(rs.getInt("w_id"), rs.getString("w_name"), rs.getString("w_tel"), rs.getString("w_note"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeDB();
		}
		return bean;
	}
	/**
	 * 添加仓库
	 * @param form
	 */
	public void addWarehouse(WarehouseForm form){
		String sql = "insert into warehouse values (?,?,?)";
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, form.getW_name());
			pstmt.setString(2, form.getW_tel());
			pstmt.setString(3, form.getW_note());
			pstmt.execute();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeDB();
		}
	}
	/**
	 * 修改仓库信息
	 * @param form
	 * @param w_id
	 */
	public void updateWarehouse(WarehouseForm form, int w_id){
		String sql = "update warehouse set w_name = ?, w_tel = ?, w_note = ? where w_id = ?";
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, form.getW_name());
			pstmt.setString(2, form.getW_tel());
			pstmt.setString(3, form.getW_note());
			pstmt.setInt(4, w_id);
			pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeDB();
		}
	}
	/**
	 * 通过id返回仓库名称
	 * @param w_id
	 * @return
	 */
	public String showW_name(int w_id){
		String tmp = "";
		String sql = "select w_name from warehouse where w_id = ?";
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setInt(1, w_id);
			rs = pstmt.executeQuery();
			if(rs.next()){
				tmp = rs.getString("w_name");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			closeDB();
		}
		return tmp;
	}
}

⌨️ 快捷键说明

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