开发者

Can we Bring two Dataset at a time and compare it

i have a ResultSet method publ开发者_如何学运维ic ResultSet getItemPurchase(String Pid) which return a Data from a database table. similarly i have another method public Resultset getItemSale(String sid). i have called them using a function ResultSet rs1 = getItemPurchase(Pid); and next function is ResultSet rs2 = getItemSale(Pid);

i want to do as following.

 1. while(rs1.next)
 2. {
 3. rs1.getString("Item");
 4.      if(rs1.getString("price")==rs2.getString("price")
 5.        {
 6.          //some code here
 7.        }
 8.      else{
 9. rs1.getDate("Purchase Date");}
 10. rs2.getString("CustomerName");
 11. }

can anybody please help me on this


I would suggest you to write two domain objects, Plain Java objects like:

public class ItemPurchase{
    private String price;

    //setter/getter for price

    private String purchaseDate;
    //setter/getter for purchaseDate
}
public class ItemSale{
  private String price;

    //setter/getter for price

    private String customerName;
    //setter/getter for customerName
}

Now create a list of objects while iterating each resultset like:

public List createListOfItemPurchased(ResultSet rs){
 List<ItemPurchase> purchaseList=new ArrayList<ItemPurchase>();
 while(rs.next()){
   ItemPurchase purchaseObject=new ItemPurchase();
   purchaseObject.setPrice(rs.getString("price"));
 //fill all required data in it
  purchaseList.add(purchaseObject);
 }
  return purchaseList;
}

Same way populate the salesObjects and then create a method to filter out your results like:

filter(List purchaseList, List salesList){
  for(ItemPurchase purchaseObj:purchaseList){
    //process the objects according to your requirement
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜