예제 #1
0
  // 查询订单全部数据-返回链表
  public static ArrayList<Order> search(String sql) throws SQLException {
    // 建立连接
    Connection dbConn = DataBaseTool.getConnection();
    // 执行sql语句
    ResultSet rs = DataBaseTool.executeQuery(dbConn, sql);
    ArrayList<Order> list = new ArrayList<Order>();
    // 结果存储
    while (rs.next()) {
      Order order = new Order();
      // int数据
      order.setId(rs.getInt("id"));
      order.setUserId(rs.getInt("userId"));
      order.setsDistribution(rs.getInt("sDistribution"));
      order.settDistribution(rs.getInt("tDistribution"));
      order.setCarId(rs.getInt("carId"));
      order.setCurrentDistribution(rs.getInt("currentDistribution"));

      // 发件人
      order.setSender(rs.getString("sender"));
      order.setsCode(rs.getString("sCode"));
      order.setsAddress(rs.getString("sAddress"));
      order.setsPhone(rs.getString("sPhone"));

      // 收件人
      order.setReceiver(rs.getString("receiver"));
      order.settCode(rs.getString("tCode"));
      order.settAddress(rs.getString("tAddress"));
      order.settPhone(rs.getString("tPhone"));

      // 订单信息
      order.setVolumn(rs.getFloat("volumn"));
      order.setWeight(rs.getFloat("weight"));
      order.setPrice(rs.getFloat("price"));
      order.setStatus(rs.getInt("status"));
      order.setGoodsType(rs.getInt("goodsType"));

      order.setRemark(rs.getString("remark"));
      order.setWorker(rs.getString("worker"));
      order.setPath(rs.getString("path"));
      order.setWorkDate(rs.getString("workDate"));
      list.add(order);
    }
    // 关闭连接
    DataBaseTool.close(rs, rs.getStatement(), dbConn);
    // 返回数据
    return list;
  }
예제 #2
0
 // 根据map进行search -- 组合查询
 public static ArrayList<Order> searchByMap(HashMap<String, String> hashMap) throws SQLException {
   Connection dbConn = DataBaseTool.getConnection();
   StringBuffer sql = new StringBuffer("select * from orders where 1=1 ");
   for (Entry<String, String> entry : hashMap.entrySet()) {
     sql.append("and " + entry.getKey() + "=" + entry.getValue() + " ");
   }
   ResultSet rs = DataBaseTool.executeQuery(dbConn, sql.toString());
   ArrayList<Order> list = new ArrayList<Order>();
   while (rs.next()) {
     Order od = new Order();
     od.setId(rs.getInt("id"));
     od.setUserId(rs.getInt("userId"));
     od.setSender(rs.getString("sender"));
     od.setsAddress(rs.getString("sAddress"));
     od.setsCode(rs.getString("sCode"));
     od.setsPhone(rs.getString("sPhone"));
     od.setsDistribution(rs.getInt("sDistribution"));
     od.setReceiver(rs.getString("receiver"));
     od.settAddress(rs.getString("tAddress"));
     od.settCode(rs.getString("tCode"));
     od.settPhone(rs.getString("tPhone"));
     od.settDistribution(rs.getInt("tDistribution"));
     od.setWorker(rs.getString("worker"));
     od.setWorkDate(rs.getString("workDate"));
     od.setVolumn(rs.getFloat("volumn"));
     od.setWeight(rs.getFloat("weight"));
     od.setPath(rs.getString("path"));
     od.setPrice(rs.getFloat("price"));
     od.setStatus(rs.getInt("status"));
     od.setCarId(rs.getInt("carId"));
     od.setCurrentDistribution(rs.getInt("currentDistribution"));
     od.setGoodsType(rs.getInt("goodsType"));
     od.setRemark(rs.getString("remark"));
     list.add(od);
   }
   DataBaseTool.close(rs, rs.getStatement(), dbConn);
   return list;
 }