?
Solved

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

Posted on 2009-04-16
2
Medium Priority
?
303 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:Fionageo
2 Comments
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 2000 total points
ID: 24156086
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
 

Author Closing Comment

by:Fionageo
ID: 31570853
Yes it works, thanks a lot!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 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