4

I am using Slick 3.x with Play 2.3.9 without play-slick because play-slick does not support this combination. I read

http://blog.knoldus.com/2015/03/03/play-with-reactive-slick-a-simple-crud-application-in-play-framework-using-slick-3-0/

And it mentioned that database connection must be closed explicitly i.e.

def delete(id: Long): Future[Int] =
    try db.run(filterQuery(id).delete)
    finally db.close

Do I have to close the connection explicitly as mentioned in the article? Will db.close closes the connection and pool? Because, OTH, the examples in Slick 3.0 document didn't close the connection explicitly. I could have misunderstood the document. Thanks

Yogeshree Koyani
  • 1,649
  • 10
  • 19
thlim
  • 2,908
  • 3
  • 34
  • 57

2 Answers2

3

db.close closes the connection pool. You probably don't want to do that. The way its written the db will likely close before the database query is processed.

db.close doesn't close connections or statements. That was automajically done for you within the db.run() clause

Andrew Norman
  • 843
  • 9
  • 22
2

I checked MySQL processes list, show processlist, and found that the application did not connect more than what was specified in the application settings and continued to accept requests more than the allowable database connections. This shows that after every request the db connection is returned to the pool within db.run(...) and db.close is not required.

thlim
  • 2,908
  • 3
  • 34
  • 57