i am using mysql in scala with play 2.2 and want to create a connection pool. I am recently find myself unable to get the code of creating connection pool. help...
-
FYI commons.apache.org/proper/commons-dbcpom-nom-nom– om-nom-nom2013-10-12 09:55:05 +00:00Commented Oct 12, 2013 at 9:55
-
1To add to om-nom-nom's comment, mchange.com/projects/c3p0 is another viable option. PS, generally on SO you should at least show your past efforts/research and aim for a more specific question than "how do I do X"waffle paradox– waffle paradox2013-10-12 13:26:09 +00:00Commented Oct 12, 2013 at 13:26
-
2Play already has connection pooling. You can get a connection with play.api.db.DB withConnection or withTransaction.Ivan Meredith– Ivan Meredith2013-10-12 22:27:05 +00:00Commented Oct 12, 2013 at 22:27
-
@IvanMeredith perhaps, that is the best answer. Dare to post it below?om-nom-nom– om-nom-nom2013-10-13 11:56:57 +00:00Commented Oct 13, 2013 at 11:56
1 Answer
As Ivan Meredith said, play already comes with a connection pool, (bonecp by default), so if you configure database access as described in the play docs (http://www.playframework.com/documentation/2.2.x/ScalaDatabase) the connections from withConnection or withTransaction will come from the connection pool.
If you want to fine-tune the connection pool almost everything seems to be supported in the config but I cannot find any docs on it so you might have to dive into the sources to find the configuration file property names.
Default configuration in Play 2.2 creates 1 partition with 5-30 connections.