How to extract values of a ITable and save its data to a csv file?

Posted on 2009-04-16
Last Modified: 2013-12-13

I am working with DBUnit and sending a query to the database ITable actualData = getConnection().createQueryTable("RESULT_NAME","Select * from districts where id=3");
assertNotNull("error", actualData); // My resultset should be always null !

and now I need to get the values of this query and save it in a CSV file together with the error message which explain where and why the error ocurr in the assertNotNull..

How can I extract this values and then write them into a file? I have tried with CsvDataSetWriter.write(actualData, "c:\\queries.cvs"); but this method required and IDataSet.
and how can I get the error message thrown by failNotEquals? because this explain where and why the error occurred and I need to catch that error message and write it together with the result of the previous question.

Thanks in advance.
Question by:Fionageo
    LVL 20

    Accepted Solution

    By having a look at the API I would suggest this code. I have to admit that I haven't wokred with DBUnit ... I just engeneered it ba having a look at the API ... so no guarantees ;-)
    ITableMetaData metaData = actualData.getTableMetaData();
    Columns[] columns = metaData.getColumns();
    for(int i = 0; i < actualData.getRowCount(); i++) {
        for(int j = 0; j < columns.length; j++) {
            String columnName = columns[j].getColumnName();
            Object columnValue = actualData.getValue(i, columnName);

    Open in new window


    Author Closing Comment

    Yes it works, thanks a lot!

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    simple redial program 3 63
    sumHeights  challenge 17 50
    Open Source: Multi-Level-Marketing software? 3 54
    countX 22 50
    Article by: Rob
    Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
    The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
    This video teaches viewers about errors in exception handling.
    Viewers will learn how to use the Hootsuite Dashboard.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now