2012-12-07 44 views
0

我需要一種方法來查看preparedStatement的調試,這裏是我的java代碼,我希望將prepareStatement打印到控制檯。有沒有什麼辦法打印準備好的語句到控制檯System.out.println

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)); 

} 

} 
+3

爲什麼不設置一個破發點,並讀出的值? – Max

+0

請告訴我更多。我不知道這一點。 – Croeber

+0

你以前從未在IDE中調試過嗎?我假設你正在使用eclipse,但是,其他IDE有很多教程。 http://www.vogella.com/articles/EclipseDebugging/article.html#usedebug_breakpoints – Max

回答

1

若要回答你的問題,我輸出我的查詢到一個日誌文件(控制檯)執行以下操作:

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

//Write stmt to console: 
System.out.println(stmt.toString()); 
1

對於查詢的調試,我通常使用的庫jamon,它是記錄每一個語句JDBC代理調用

相關問題