Anorm select fails with OutOfMemory on big tables

100 views Asked by At

executing this query fails with OutOfMemoryError if the table is too big:

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)

how to solve it?

how can I get an Iterator or Stream (instead of a Seq) so that it can handle any table size?

Update

this code (which does not use anorm) works well on big tables:

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)
}

So, I tried with anorm as follows, but without success:

   val names: Seq[String] = SQL"select name from persons".withFetchSize(Some(Integer.MIN_VALUE)).as(SqlParser.str("name").*)
0

There are 0 answers