Пример #1
0
 @Override
 public List<ServiceValue> getlist() throws Exception {
   List<ServiceValue> serlist = new ArrayList<ServiceValue>();
   String sql =
       "SELECT `service`.*, `client`.`clientname` FROM `carsell`.`service`"
           + "INNER JOIN `carsell`.`client` ON (`service`.`clientid` = `client`.`clientid`)";
   Connection cn = null;
   try {
     cn = ConnectionFactory.getConnection();
     PreparedStatement ps = cn.prepareStatement(sql);
     ResultSet rs = ps.executeQuery();
     while (rs.next()) {
       ServiceValue ssv = new ServiceValue();
       ssv.setSerid(rs.getInt("serid"));
       ssv.setSerdate(rs.getString("serdate"));
       ssv.setSerstate(rs.getString("serstate"));
       ssv.setClientid(rs.getInt("clientid"));
       ssv.setClientname(rs.getString("clientname"));
       serlist.add(ssv);
     }
     rs.close();
     ps.close();
   } catch (Exception e) {
     throw new Exception("获取服务列表DAO错误:" + e.getMessage());
   } finally {
     cn.close();
   }
   return serlist;
 }
Пример #2
0
 @Override
 public ServiceValue get(int serid) throws Exception {
   ServiceValue ssv = null;
   String sql =
       "SELECT `service`.*, `client`.`clientname` FROM `carsell`.`service`"
           + "INNER JOIN `carsell`.`client` ON (`service`.`clientid` = `client`.`clientid`) WHERE `serid`=?";
   Connection cn = null;
   try {
     cn = ConnectionFactory.getConnection();
     PreparedStatement ps = cn.prepareStatement(sql);
     ps.setInt(1, serid);
     ResultSet rs = ps.executeQuery();
     while (rs.next()) {
       ssv = new ServiceValue();
       ssv.setSerid(rs.getInt("serid"));
       ssv.setSerdate(rs.getString("serdate"));
       ssv.setSerstate(rs.getString("serstate"));
       ssv.setClientid(rs.getInt("clientid"));
       ssv.setClientname(rs.getString("clientname"));
     }
     rs.close();
     ps.close();
   } catch (Exception e) {
     throw new Exception("根据id获取服务信息DAO错误:" + e.getMessage());
   } finally {
     cn.close();
   }
   return ssv;
 }