Java Iterator backed by a ResultSet

后端 未结 17 753
清歌不尽
清歌不尽 2020-12-13 06:51

I\'ve got a class that implements Iterator with a ResultSet as a data member. Essentially the class looks like this:

public class A implements Iterator{
            


        
17条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 07:23

    One option is the ResultSetIterator from the Apache DBUtils project.

    BalusC rightly points out the the various concerns in doing this. You need to be very careful to properly handle the connection/resultset lifecycle. Fortunately, the DBUtils project also has solutions for safely working with resultsets.

    If BalusC's solution is impractical for you (e.g. you are processing large datasets that can't all fit in memory) you might want to give it a shot.

提交回复
热议问题