0

この QUERY をデータベースに送信すると、両方のデータベースに手動でクエリを入力すると正しいデータが返されるにもかかわらず、アサーション エラーが発生し続けます。これらの 2 つのカウントをどのように比較すればよいか教えていただけますか??

唯一の違いは、列のタイトルです。以下に文字どおり表示されています (左が MYSQL、右が MSSQL)。

これがクエリと結果です

select count(userfieldid) from tr_userfield where calcexpression like '%@004%' and usefor like '%B%'

_____________________________________________
count(*)     |     (No Column Name)
_____________________________________________
43           |           43
             |

ここに私のJAVAコードがあります

package a7.unittests.dao;

import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.ResultSet;
import org.junit.Test;
import java.sql.PreparedStatement;
import artemispm.autocalc.TRBaseScoreCalculator;

public class UnitTestTRBaseScoreCalculator_Select {
@Test
public void testQUERY_ISTHISCHARACINUSE() throws Exception{

    char WILDCARD = '%';

    UnitTestHelper helper = new UnitTestHelper();
    Connection con = helper.getConnection(helper.sourceDBUrl);
    Connection conTarget = helper.getConnection(helper.targetDBUrl);

    PreparedStatement stmt = con.prepareStatement(String.format(TRBaseScoreCalculator.QUERY_ISTHISCHARINUSE_1, WILDCARD, "@004", WILDCARD, WILDCARD, "B", WILDCARD));
    ResultSet sourceVal = stmt.executeQuery();
    stmt = conTarget.prepareStatement(String.format(TRBaseScoreCalculator.QUERY_ISTHISCHARINUSE_1, WILDCARD, "@004", WILDCARD, WILDCARD, "B", WILDCARD));
    ResultSet targetVal = stmt.executeQuery();
    assertTrue(helper.resultSetsEqual2(sourceVal,targetVal));   }

}

package a7.unittests.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class UnitTestHelper {




public Connection getConnection(String url)throws Exception{
    return DriverManager.getConnection(url);
}

/*
 * Use for Insert and Update and Delete Statements
 */

public boolean resultSetsEqual4 (int source, int target){

    System.out.println("The source is: "+source+" The target is: "+target);
    if(((source>0)&&(target>0)&&(target==source)))
    {

        return true;
    }
    else
    {
        return false;
    }
}

/*
 * Used to test SELECT statements passing in objects
 */


public boolean resultSetsEqual2 (ResultSet source, ResultSet target) throws SQLException{
    System.out.println("The source is: "+source+" The target is: "+target);
    while(source.next())
    {
        target.next();
        ResultSetMetaData metadata = source.getMetaData();
        int count = metadata.getColumnCount();
        for (int i =1; i<=count; i++)
        {
            if(!source.getObject(i).equals(target.getObject(i)))
            {return false;}
        }
    }
    return true;
}


public boolean resultSetsEqual (ResultSet source, ResultSet target) throws SQLException{

System.out.println("The source is: "+source+" The target is: "+target);
while(source.next())
{
    target.next();
    ResultSetMetaData metadata = source.getMetaData();
    int count = metadata.getColumnCount();
    for (int i =1; i<=count; i++)
    {
        if(source.getObject(i) != target.getObject(i))
        {return false;}
    }
}
return true;
}
public boolean resultSetsEqual3 (ResultSet rs1, ResultSet rs2) throws SQLException {
int col = 1;
//ResultSetMetaData metadata = rs1.getMetaData();
//int count = metadata.getColumnCount();
while (rs1.next() && rs2.next()) {
    final Object res1 = rs1.getObject(col);
    final Object res2 = rs2.getObject(col);
    // Check values
    if (!res1.equals(res2)) {
        throw new RuntimeException(String.format("%s and %s aren't equal at common position %d",
            res1, res2, col));
    }
    // rs1 and rs2 must reach last row in the same iteration
    if ((rs1.isLast() != rs2.isLast())) {
        throw new RuntimeException("The two ResultSets contains different number of columns!");
    }  
}
return true;
}
}
4

0 に答える 0