1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
| package com.wanczy.dao.impl;
import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List;
import com.wanczy.dao.CustomerResourceDAO; import com.wanczy.pojo.CustomerResourcePOJO;
public class CustomerResourceDAOImpl implements CustomerResourceDAO { Connection conn ; public CustomerResourceDAOImpl(Connection conn){ this.conn = conn; } public boolean doDel(BigDecimal cID) { boolean flag = false; PreparedStatement pstate = null; try { this.conn.setAutoCommit(false); String sql = "delete from customer_resource where c_id = ?"; pstate = this.conn.prepareStatement(sql); pstate.setBigDecimal(1, cID); pstate.execute(); this.conn.commit(); flag = true; } catch (Exception e) { e.printStackTrace(); try { this.conn.rollback(); } catch (Exception e2) { e2.printStackTrace(); } } finally{ try { pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return flag; }
public boolean doIns(CustomerResourcePOJO pojo) { boolean flag = false; PreparedStatement pstate = null; try { this.conn.setAutoCommit(false); String sql = "insert into customer_resource (c_id, s_name, s_add, " + "s_link_man, s_link_tel, c_level, c_state ,s_leader, s_leader_tel)" + "values(scott_squence.nextval,?,?,?,?,?,?,?,?)"; pstate = this.conn.prepareStatement(sql); pstate.setString(1,pojo.getSname()); pstate.setString(2,pojo.getSadd()); pstate.setString(3,pojo.getSlinkMan()); pstate.setString(4,pojo.getSlinkTel()); pstate.setInt(5,pojo.getClevel()); pstate.setInt(6,pojo.getCstate()); pstate.setString(7,pojo.getSleader()); pstate.setString(8,pojo.getSleaderTel()); pstate.execute(); this.conn.commit(); flag = true; } catch (Exception e) { e.printStackTrace(); try { this.conn.rollback(); } catch (Exception e2) { e2.printStackTrace(); } } finally{ try { pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return flag; }
public boolean doUpd(CustomerResourcePOJO pojo) { boolean flag = false; PreparedStatement pstate = null; try { this.conn.setAutoCommit(false); String sql = "update customer_resource set s_name=?, s_add=?, " + " s_link_man=?, s_link_tel=?, c_level=?, c_state=? ,s_leader=?, s_leader_tel=? where" + " c_id = ?"; pstate = this.conn.prepareStatement(sql); pstate.setString(1,pojo.getSname()); pstate.setString(2,pojo.getSadd()); pstate.setString(3,pojo.getSlinkMan()); pstate.setString(4,pojo.getSlinkTel()); pstate.setInt(5,pojo.getClevel()); pstate.setInt(6,pojo.getCstate()); pstate.setString(7,pojo.getSleader()); pstate.setString(8,pojo.getSleaderTel()); pstate.setBigDecimal(9, pojo.getCid()); pstate.execute(); this.conn.commit(); flag = true; } catch (Exception e) { e.printStackTrace(); try { this.conn.rollback(); } catch (Exception e2) { e2.printStackTrace(); } } finally{ try { pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return flag; }
public CustomerResourcePOJO findByCId(BigDecimal cID) { CustomerResourcePOJO pojo = null; PreparedStatement pstate = null; ResultSet res = null; try { String sql = "select s_name, s_add, " + "s_link_man, s_link_tel, c_level, c_state ,s_leader, s_leader_tel from customer_resource where c_id = ?"; pstate = this.conn.prepareStatement(sql); pstate.setBigDecimal(1, cID); res = pstate.executeQuery(); while(res.next()){ pojo = new CustomerResourcePOJO(cID,res.getString(1),res.getString(2), res.getString(3),res.getString(4),res.getInt(5),res.getInt(6), res.getString(7),res.getString(8)); } } catch (Exception e) { e.printStackTrace(); } finally{ try { res.close(); pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return pojo; }
public List<CustomerResourcePOJO> findByNameLevelState(String sName, int cLevel, int cState, int pageSize, int pageCurrent) { List<CustomerResourcePOJO> list = new ArrayList<CustomerResourcePOJO>(); PreparedStatement pstate = null; ResultSet res = null; try { StringBuffer sql = new StringBuffer(); sql.append("select c_id,s_name, s_add, s_link_man, "+ " s_link_tel, c_level, c_state ,s_leader, "+ " s_leader_tel from (select c_id,s_name, s_add, s_link_man, "+ " s_link_tel, c_level, c_state ,s_leader, "+ " s_leader_tel ,rownum abc "+ " from customer_resource where s_name like ? "); if(cLevel != 0){ sql.append(" and c_level = "+cLevel); } if(cState != 0){ sql.append(" and c_state = "+cState); } sql.append(" ) where abc>? and abc<=? order by c_level,c_state"); pstate = this.conn.prepareStatement(sql.toString()); pstate.setString(1, "%"+sName+"%"); pstate.setInt(2, (pageCurrent-1)*pageSize); pstate.setInt(3, pageCurrent*pageSize); res = pstate.executeQuery(); while(res.next()){ CustomerResourcePOJO pojo = new CustomerResourcePOJO(res.getBigDecimal(1),res.getString(2),res.getString(3), res.getString(4),res.getString(5),res.getInt(6),res.getInt(7), res.getString(8),res.getString(9)); list.add(pojo); } } catch (Exception e) { e.printStackTrace(); } finally{ try { res.close(); pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return list; }
public int findCountByNameLevelState(String sName, int cLevel, int cState) { int count = 0; PreparedStatement pstate = null; ResultSet res = null; try { StringBuffer sql = new StringBuffer(); sql.append("select count(c_id) from customer_resource where s_name like ? "); if(cLevel != 0){ sql.append(" and c_level = "+cLevel); } if(cState != 0){ sql.append(" and c_state = "+cState); } pstate = this.conn.prepareStatement(sql.toString()); pstate.setString(1, "%"+sName+"%"); res = pstate.executeQuery(); while(res.next()){ count = res.getInt(1); } } catch (Exception e) { e.printStackTrace(); } finally{ try { res.close(); pstate.close(); } catch (Exception e2) { e2.printStackTrace(); } } return
|