0

ここでデバッグ用のpreparedStatementを表示する方法が必要です。これは、preparedStatementをコンソールに出力するJavaコードです。

public class UnitTestDMUtility_Select {


@Test
public void testQUERY_CHECKBOTHPARTS() throws Exception{

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


    PreparedStatement stmt = con.prepareStatement(DMUtility.QUERY_CHECKBOTHPARTS);
    stmt.setInt(1, 101);
    ResultSet sourceVal = stmt.executeQuery();
    //Here is the QUERY
    //select count(*) from tr_demand where demandtypeid=101
    stmt = conTarget.prepareStatement(DMUtility.QUERY_CHECKBOTHPARTS);
    stmt.setInt(1, 101);
    ResultSet targetVal = stmt.executeQuery();

    assertTrue(helper.resultSetsEqual2(sourceVal,targetVal));

}

} 
4

2 に答える 2

1

For query debug I usually use the library jamon, it is a JDBC proxy that logs every statement is invoked

于 2012-12-07T14:22:06.767 に答える
1

To answer your question, I output my queries to a log file ( and console ) by doing the following:

PreparedStatement stmt = con.prepareStatement(DMUtility.QUERY_CHECKBOTHPARTS);
stmt.setInt(1, 101);

//Write stmt to console: 
System.out.println(stmt.toString());
于 2012-12-07T14:28:08.230 に答える