storagedao.java
来自「struts做得固定资产管理系统 带毕业论文完整版」· Java 代码 · 共 153 行
JAVA
153 行
package com.qrsx.appcam.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.qrsx.appcam.model.Storage;
public class StorageDAO extends BaseDAO {
/**
* 创建仓库
*
* @param storage
*/
public void create(Storage storage) throws SQLException {
String sql = "Insert Into storage(name, description) Values(?, ?)";
// 设置参数值
ps = conn.prepareStatement(sql);
ps.setString(1, storage.getName());
ps.setString(2, storage.getDescription());
// 执行
ps.executeUpdate();
}
/**
* 更新仓库信息
*
* @param storage
*/
public void update(Storage storage) throws SQLException {
String sql = "Update deptment set name=?, description=? where id=? ";
// 设置参数值
ps = conn.prepareStatement(sql);
ps.setString(1, storage.getName());
ps.setString(2, storage.getDescription());
ps.setInt(3, storage.getId());
// 执行
ps.executeUpdate();
}
/**
* 删除仓库
*
* @param storageId
* 要删除的仓库的主键
* @return 删除的数目
*/
public int delete(Integer storageId) throws SQLException {
String sql = "Delete from storage where id=? ";
// 设置参数值
ps = conn.prepareStatement(sql);
ps.setInt(1, storageId);
// 执行
int total = ps.executeUpdate();
return total;
}
/**
* 根据主键检索仓库
*
* @param storageId
* 要检索的仓库主键
* @return 检索到的仓库
*/
public Storage findById(Integer storageId) throws SQLException {
String sql = "Select * from storage where id=? ";
// 设置参数值并执行查询
ps = conn.prepareStatement(sql);
ps.setInt(1, storageId);
ResultSet rs = ps.executeQuery();
Storage storage = null;
if (rs.next()) {
storage = new Storage();
storage.setId(rs.getInt("id"));
storage.setName(rs.getString("name"));
storage.setDescription(rs.getString("description"));
}
return storage;
}
/**
* 检索所有的仓库信息
*
* @return List<Storage>
* @throws SQLException
*/
public List<Storage> findAll() throws SQLException {
String sql = "Select * from Storage ";
// 执行查询
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
// 将查询结果组装至deptment实体对象
Storage storage = null;
List<Storage> list = new ArrayList<Storage>();
while (rs.next()) {
storage = new Storage();
storage.setId(rs.getInt("id"));
storage.setName(rs.getString("name"));
storage.setDescription(rs.getString("description"));
list.add(storage);
}
return list;
}
/**
* 检索所有仓库的信息
*
* @param storage
* @return List<Storage>
* @throws SQLException
*/
public List<Storage> list(Storage storage) throws SQLException {
String sql = "Select * from storage where 1=1 ";
// 根据仓库名称检索
if (storage.getName() != null && !storage.getName().equals("")) {
sql = sql + " and name like '%" + storage.getName() + "%'";
}
// 执行查询
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
// 将查询结果组装至storage实体对象
Storage storage1 = null;
List<Storage> list = new ArrayList<Storage>();
while (rs.next()) {
storage1 = new Storage();
storage1.setId(rs.getInt("id"));
storage1.setName(rs.getString("name"));
storage1.setDescription(rs.getString("description"));
list.add(storage1);
}
return list;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?