我们可以一次带来两个数据集并进行比较吗

发布于 2024-11-08 05:04:10 字数 636 浏览 3 评论 0原文

我有一个 ResultSet 方法 public ResultSet getItemPurchase(String Pid) 它从数据库表返回数据。类似地,我有另一个方法 public Resultset getItemSale(String sid)。 我使用函数 ResultSet rs1 = getItemPurchase(Pid); 调用它们,下一个函数是 ResultSet rs2 = getItemSale(Pid);

我想执行以下操作。

 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. }

有人可以帮我解决这个问题吗

i have a ResultSet method public 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风起 2024-11-15 05:04:10

我建议您编写两个域对象,即纯 Java 对象,例如:

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
}

现在在迭代每个结果集时创建一个对象列表,例如:

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;
}

以相同的方式填充 salesObjects,然后创建一个方法来过滤结果,例如:

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

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
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文