[英]Comparing two resultset of two different tables
In the below code I am comparing the two Resultset of the tables S_R_VAL and R_VAL. 在下面的代码中,我正在比较表S_R_VAL和R_VAL的两个结果集。 I need to compare S_NUMBER (from S_R_VAL table) and S_NO (from R_VAL table).
我需要比较S_NUMBER(来自S_R_VAL表)和S_NO(来自R_VAL表)。 While comparing I am getting this error "java.lang.RuntimeException: The two ResultSets contains different number of columns! . Please help in fixing this error.
比较时,我收到此错误“ java.lang.RuntimeException:两个ResultSet包含不同的列数! 。请帮助解决此错误。
String SSQ = "select DISTINCT S_NUMBER from OTG.S_R_VAL" +
" WHERE R_TS = (SELECT MAX(R_TS) FROM OTG.S_R_VAL) order by S_NUMBER";
String SDS = "SELECT DISTINCT S_NUMBER FROM OTG.S_R_VAL AS STG WHERE S_NUMBER NOT IN" +
"(SELECT S_NO FROM OTG.R_VAL AS REV WHERE STG.S_NUMBER = REV.S_NO )";
String SSR = "SELECT DISTINCT S_NO FROM OTG.R_VAL where S_NO != 'NULL' order by S_NO";
String SSO = "Select O_UID from OTG.OPTY where C_S_NO IN" +
"( SELECT DISTINCT S_NUMBER FROM OTG.S_R_VAL AS STG WHERE S_NUMBER NOT IN(SELECT S_NO FROM OTG.R_VAL AS REV WHERE STG.S_NUMBER = REV.S_NO ))";
//Statement statement;
try {
connection = DatabaseConnection.getCon();
statement = connection.createStatement();
statement1 = connection.createStatement();
ResultSet SQ = statement.executeQuery(SSQ);
ResultSet DS = statement.executeQuery(SDS);
ResultSet SR = statement.executeQuery(SSR);
ResultSet SO = statement.executeQuery(SSO);
while (rs.next() && SR.next(){
String res1 = rs.getString("S_NUMBER");
String res2 = SR.getString("S_NO");
StringBuffer updateQuery = new StringBuffer();
if (res1.equals(res2)) {
throw new RuntimeException(String.format("%s and %s aren't equal at common position %d",
res1, res2));
}else
{
throw new RuntimeException("The two ResultSets contains different number of columns!");
}
}
connection.commit();
You can't reuse the same Statement
object because on every new executeQuery()
call any ResultSet
if already open is closed implicitly. 您不能重复使用同一
Statement
对象,因为在每个新的executeQuery()
如果已隐式关闭已打开的任何ResultSet
则会调用该方法。
A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
当关闭,重新执行或用于生成多个结果序列中的下一个结果的Statement对象时,将自动关闭ResultSet对象。
Check out the JavaDocs for ResultSet . 签出ResultSet的JavaDocs。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.