コード例 #1
0
 public Customer create(Customer entity) throws Exception {
   DBean db = new DBean();
   PreparedStatement ps = null;
   StringBuffer sb = new StringBuffer();
   sb.append("Insert into Customer(");
   sb.append("customerId,");
   sb.append("customerName,");
   sb.append("contectPerson,");
   sb.append("district,");
   sb.append("postcode,");
   sb.append("address,");
   sb.append("mobile,");
   sb.append("phone,");
   sb.append("fax,");
   sb.append("url,");
   sb.append("email,");
   sb.append("accountBank,");
   sb.append("accountNumber,");
   sb.append("accountPerson,");
   sb.append("mark,");
   sb.append("customerPinYin,");
   sb.append("abstractCustomer,");
   sb.append("insertDate");
   sb.append(") values(");
   for (int i = 0; i < 18; i++) {
     sb.append(i == 0 ? "?" : ",?");
   }
   sb.append(")");
   try {
     Connection con = db.getConnection();
     ps = con.prepareStatement(sb.toString());
     int pos = 1;
     ps.setString(pos++, entity.getCustomerId());
     ps.setString(pos++, entity.getCustomerName());
     ps.setString(pos++, entity.getContectPerson());
     ps.setString(pos++, entity.getDistrict());
     ps.setString(pos++, entity.getPostcode());
     ps.setString(pos++, entity.getAddress());
     ps.setString(pos++, entity.getMobile());
     ps.setString(pos++, entity.getPhone());
     ps.setString(pos++, entity.getFax());
     ps.setString(pos++, entity.getUrl());
     ps.setString(pos++, entity.getEmail());
     ps.setString(pos++, entity.getAccountBank());
     ps.setString(pos++, entity.getAccountNumber());
     ps.setString(pos++, entity.getAccountPerson());
     ps.setString(pos++, entity.getMark());
     ps.setString(pos++, entity.getCustomerPinYin());
     ps.setString(pos++, entity.getAbstractCustomer());
     ps.setDate(pos++, DateUtils.toSqlDate(entity.getInsertDate()));
     ps.execute();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     db.closeAll(null, ps, db);
   }
   return entity;
 }
コード例 #2
0
 public void update(Customer entity) throws Exception {
   DBean db = new DBean();
   PreparedStatement ps = null;
   StringBuffer sb = new StringBuffer();
   sb.append("Update Customer set ");
   sb.append("customerName=?,");
   sb.append("contectPerson=?,");
   sb.append("district=?,");
   sb.append("postcode=?,");
   sb.append("address=?,");
   sb.append("mobile=?,");
   sb.append("phone=?,");
   sb.append("fax=?,");
   sb.append("url=?,");
   sb.append("email=?,");
   sb.append("accountBank=?,");
   sb.append("accountNumber=?,");
   sb.append("accountPerson=?,");
   sb.append("mark=?,");
   sb.append("customerPinYin=?,");
   sb.append("abstractCustomer=?,");
   sb.append("insertDate=?");
   sb.append(" where customerId = ?");
   try {
     Connection con = db.getConnection();
     ps = con.prepareStatement(sb.toString());
     int pos = 1;
     ps.setString(pos++, entity.getCustomerName());
     ps.setString(pos++, entity.getContectPerson());
     ps.setString(pos++, entity.getDistrict());
     ps.setString(pos++, entity.getPostcode());
     ps.setString(pos++, entity.getAddress());
     ps.setString(pos++, entity.getMobile());
     ps.setString(pos++, entity.getPhone());
     ps.setString(pos++, entity.getFax());
     ps.setString(pos++, entity.getUrl());
     ps.setString(pos++, entity.getEmail());
     ps.setString(pos++, entity.getAccountBank());
     ps.setString(pos++, entity.getAccountNumber());
     ps.setString(pos++, entity.getAccountPerson());
     ps.setString(pos++, entity.getMark());
     ps.setString(pos++, entity.getCustomerPinYin());
     ps.setString(pos++, entity.getAbstractCustomer());
     ps.setDate(pos++, DateUtils.toSqlDate(entity.getInsertDate()));
     ps.setString(pos++, entity.getCustomerId());
     ps.execute();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     db.closeAll(null, ps, db);
   }
 }