I have Employee table and an Entity class for it,
My task is such that i need the data of employee table within result set(of type scrollable) two times,
in such case what would be better of the following for using the data second time ->
1: create instance of entity class and store it in List while iterating through result set for first time.
OR
2: after first iteration call the first() method of result set to go back to first row and use data for second time.
Which option will consume less time and resources.
If You have better suggestions, please provide.
Thanks.
Unless this is about very large resultsets, you’re probably much better off consuming the whole JDBC
ResultSetinto memory and operating on ajava.util.Listrather than on ajava.sql.ResultSetfor these reasons:ResultSet, as various JDBC drivers implement this functionality just subtly differentlyYou can use tools for consuming JDBC result sets. For instance Apache DbUtils:
jOOQ (3.0 syntax):
Spring JdbcTemplate: