如何在Java中加入ResultSet对象? [英] How to join ResultSet objects in java?
本文介绍了如何在Java中加入ResultSet对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个联系.
Connection cone = ... // to DB2
Statement statement = cone.createStatement();
ResultSet resultSet1 = statement.executeQuery("select * from tableone");
Connection ctwo = ... // to Teradata
Statement statement = ctwo .createStatement();
ResultSet resultSet2 = statement.executeQuery("select * from tabletwo");
如何连接这两个表?
到目前为止,我正在使用opencsv API将上述结果集写入csv.然后操作两个csv文件.我确信我的方法远非理想,需要时间且效率不高
so far i am writing the above result sets to csv using opencsv API . And then manipulate the two csv files . I am sure my approach is far from ideal , it takes time and not efficient
必须有一个有效的解决方案.毕竟,这两个结果集是java对象.必须有一种无需第三方API即可加入他们的方式
推荐答案
如上所述,在DB2中创建一个临时表可能不是最好的方法.完全是由于权限限制.问题清楚地问,如何将两个结果集对象连接起来.
Creating a temporary table in DB2 as it was mentioned , might not be the best way . Simply due to permission restrictions . The question asks clearly , how to join two result set objects.
我相信Stackoveflow上有一个 answer
I believe there was an answer on Stackoveflow
while (rs1.next) {
YourClass obj = new YourClass();
obj.setSomeProperty(rs.getString(1));
obj.setAnotherProperty(rs.getString(2));
// etc..
cominbedDataSet.add(obj);
}
祝你好运
这篇关于如何在Java中加入ResultSet对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文