Re: Squeryl NOOB: java.sql.SQLException: Operation not allowed after ResultSet closed

195 views
Skip to first unread message

David Whittaker

unread,
Jul 20, 2017, 10:33:30 AM7/20/17
to squ...@googlegroups.com
Hi Marco,

I assume you figured this out, but the what you get from your query is a Seq that will lazily load and convert data from the result set.  When you exit the transaction block, the result set is closed.  Because what you have is already a Seq, your .toSeq call does nothing.  If you change it to .toList, you’ll get back a realized list of values that can be accessed outside of the block.

On Jun 28, 2017, 10:00 AM -0400, Marco Mistroni <mmis...@gmail.com>, wrote:
Hello all
 i was wondering if someone can assist me here as i am a squeryl noob
So, i have the following simple code which keeps on erroring out giving me java.sql.SQLException: Operation not allowed after ResultSet closed
        trait DBConnector {
            Class.forName("com.mysql.jdbc.Driver");
            SessionFactory.concreteFactory = Some(() =>
            Session.create(
                 java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/cameldb",
                      "xx", "xxxx"),
          new MySQLAdapter()))
         }

        class SquerylPersistenceService extends PersistenceService with DBConnector{
   
               import SharesSchema._
   
               def findAllShares: Seq[Share] = {
                    transaction  {
                          println("Begin")
                          val res = from(SharesSchema.shares)(share => select(share)).iterator// replace with Iterator. we dont
                                                                         // need to consume everythingUsers
                          println("end")
                          res.toSeq
                    }
               }

where i am trying to read the shares table from the database.
All i want to have a back is  a Seq[Share]

so , every time i try to do something (such as calling .size) on the object returndby this method, i keep on getting


java.sql.SQLException: Operation not allowed after ResultSet closed
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:959)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:862)
  at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:743)
  at com.mysql.jdbc.ResultSetImpl.next(ResultSetImpl.java:6320)
  at org.squeryl.dsl.AbstractQuery$$anon$1._next(AbstractQuery.scala:214)

Could anyone tell me what am i doing wrong?
kind regards
 Marco

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages