Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert java.util.List to ResultSet?

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

like image 668
membersound Avatar asked Feb 22 '23 06:02

membersound


1 Answers

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.

like image 128
Benoit Courtine Avatar answered Feb 27 '23 14:02

Benoit Courtine