package dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import entity.Config; /** * @author Administrator *配置的数据库处理类 * 对应数据库CONFIG表 */ public class ConfigDao { DBconn conn = new DBconn(); //在数据库中添加配置 public boolean add(Config con){ return conn.update("insert into Config(CONFIGNAME,CONFIGVALUE) values(?,?)", new String[]{con.getConfigName(),con.getConfigValue()})>0; } //根据配置id来删除配置 public boolean deleteById(int configId){ return conn.update("delete from Config where configId=?", new String[]{String.valueOf(configId)})>0; } //根据配置对象来更新配置 public boolean updateByConfig(Config con){ return conn.update("update Config set CONFIGNAME=?,CONFIGVALUE=? where configId=?", new String[]{con.getConfigName(), con.getConfigValue(), String.valueOf(con.getConfigId())})>0; } /** * @param configId * @return根据ID查询数据 */ public Config queryById(int configId){ Config con=new Config(); con.setConfigId(configId); ResultSet rs=conn.query("select * from Config where configId=?", new String[]{String.valueOf(con.getConfigId())}); try { while(rs.next()){ con.setConfigId(rs.getInt("configId")); //编号 con.setConfigName(rs.getString("configName")); //名称 con.setConfigValue(rs.getString("CONFIGVALUE")); //值 } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ conn.closeAll(); } return con; } /** * @return * 返回所有的配置数据 */ public ArrayList<Config> queryAll(){ ArrayList<Config> list=new ArrayList<Config>(); ResultSet rs=conn.query("select * from Config order by configId ", null); try { while(rs.next()){ Config con=new Config(rs.getInt("configId"), rs.getString("configName"), rs.getString("configValue")); list.add(con); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ conn.closeAll(); } return list; } /** * @param configId * @return根据名称查询数据 */ public ArrayList<Config> queryByName(String configName){ Config con=new Config(); ArrayList<Config> list=new ArrayList<Config>(); ResultSet rs=conn.query("select * from Config where configName=?", new String[]{String.valueOf(configName)}); try { while(rs.next()){ con.setConfigId(rs.getInt("configId")); //编号 con.setConfigName(rs.getString("configName")); //名称 con.setConfigValue(rs.getString("configValue")); //值 list.add(con); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ conn.closeAll(); } return list; } }

202105013142 LV1
2024年1月29日
komorebi123987 LV5
2023年12月9日
2816681380 LV2
2023年1月30日
wanglinddad LV55
2022年4月15日
微信网友_5870618216976384 LV6
2022年3月14日
lishangchen LV3
2022年1月27日
sovy030201 LV5
2022年1月11日
765105637 LV9
2022年1月11日
八七 LV8
2022年1月3日
北有深秋 LV3
2021年12月21日

kingwjay LV2
5月21日
cassie555 LV3
1月16日
dongandmin LV9
2024年12月31日
appppp LV1
2024年12月12日
微信网友_7290996505972736 LV4
2024年12月11日
chinajy LV2
2024年12月8日
Daima000 LV4
2024年12月3日
Rucoding LV8
2024年11月18日
微信网友_7249860635152384
2024年11月11日
暂无贡献等级
求学的熊猫 LV11
2024年9月24日