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

Hello:

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.
Fiona
FionageoAsked:
Who is Participating?
 
ChristoferDutzConnect With a Mentor Commented:
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

0
 
FionageoAuthor Commented:
Yes it works, thanks a lot!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.