以下のコードでは、テーブル S_R_VAL と R_VAL の 2 つの結果セットを比較しています。S_NUMBER (S_R_VAL テーブルから) と S_NO (R_VAL テーブルから) を比較する必要があります。比較中に、「java.lang.RuntimeException: The two ResultSets contains different number of columns!」というエラーが表示されます。このエラーの修正にご協力ください。
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();