执行此查询将失败并显示OutOfMemoryError
:
import anorm._
Class.forName("com.mysql.jdbc.Driver").newInstance()
implicit val conn = java.sql.DriverManager.getConnection(dbUrl)
val names: Seq[String] = SQL"select name from persons".as(SqlParser.str("name").*)
names.foreach(println)
如何解决?
如何获取Iterator
或Stream
(而不是Seq
)以便它可以处理任何表格大小?
更新
此代码(不使用anorm)适用于大表:
val stmt = conn.createStatement()
stmt.setFetchSize(Integer.MIN_VALUE) // mysql driver fails with OutOfMemory without this
val rs: ResultSet = stmt.executeQuery("select name from persons")
while (rs.next()) {
val name = rs.getString(1)
println(name)
}
所以,我尝试使用anorm如下,但没有成功:
val names: Seq[String] = SQL"select name from persons".withFetchSize(Some(Integer.MIN_VALUE)).as(SqlParser.str("name").*)