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
1月29日
komorebi123987 LV5
2023年12月9日
2816681380 LV2
2023年1月30日
wanglinddad LV54
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日
最近浏览更多
人间蒸发 LV23
3月4日
刘自盛 LV2
3月1日
eagerwujin LV4
2月22日
202105013142 LV1
1月22日
微笑刺客 LV15
1月3日
落叶乌龟
1月3日
暂无贡献等级
wttttts LV2
1月1日
微信网友_6797846869299200 LV7
1月1日
微信网友_6796920618979328 LV1
2023年12月27日
pangzhihui LV12
2023年12月27日