Treating an SQL ResultSet like a Scala Stream

前端 未结 10 2240
天涯浪人
天涯浪人 2020-12-02 10:11

When I query a database and receive a (forward-only, read-only) ResultSet back, the ResultSet acts like a list of database rows.

I am trying to find some way to trea

10条回答
  •  醉梦人生
    2020-12-02 10:21

    I think most of above implementations has a nondeterministic hasNext method. Calling it two times will move cursor to the second row. I would advise to use something like that:

      new Iterator[ResultSet] {
        def hasNext = {
          !resultSet.isLast
        }
        def next() = {
          resultSet.next()
          resultSet
        }
      }
    

提交回复
热议问题