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