4

I need a ResultSet for quick database export with openCSV. What I have is a List that is retrieved from a named hibernate query.

How can I convert this list to resultset, in order to save it?

ty

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • Duplicates http://stackoverflow.com/questions/5296616/retrieving-hibernate-query-result-as-result-set-instead-of-list – Yves Martin Mar 03 '12 at 17:55
  • 2
    You can pass a `List` to the CSVWriter: http://opencsv.sourceforge.net/apidocs/au/com/bytecode/opencsv/CSVWriter.html#writeAll(java.util.List) –  Mar 03 '12 at 18:01
  • Ok yes, I can pass a List to CSVWriter. But what if (in my case) I have a List? And what is more, what if this class contains a composition of another Class? Actually I'm looking for something similar to JAXB, but for CSV instead xml. – membersound Mar 03 '12 at 19:02

1 Answers1

8

ResultSet is an interface. So, the only thing you have to do is create your own implementation, using your list values.

public class MyResultSet implements ResultSet {

    public ResultSet(List<MyClass> list) {
        // ...
    }

    // Interface implementation. For example, the "next()" method can be implemented
    // using your list iterator.
}

Then, you create an instance of MyResulSet with your list, and give it to the OpenCSV API.

Benoit Courtine
  • 7,014
  • 31
  • 42