I have a Java service running in Tomcat that makes some tens of short database reads from a MySQL database per second. Obviously, I need a DataSource with connection pooling. I obtain the connection string from a secure storage at run-time, so the most known way of obtaining a DataSource instance via JNDI from container does not seem to be applicable in my case.
I found 2 possible solutions and I'm hesitating between them.
- Creating a MysqlConnectionPoolDataSource instance in my code - appeals to me more because it is not coupled with a specific container. However, this post claims that this is totally wrong.
- Using Tomcat's DataSource and PoolProperties from org.apache.tomcat.jdbc.pool as in the "Plain Ol' Java" example