Validating MySQL database Connection when fetched from a pool using DataSource
My friend was using Tomcat and MySQL database. He had configured a datasource and as his web application was relatively new, users to his website were very less. As a result the connections were timed out after the default timeout period and exceptions were thrown.
One of the solution to avoid this scenario is to add attributes to validate the connection when borrowing.
<Context path="" reloadable="false" docBase="/home/pathtoapp"> <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxActive="30" maxIdle="10" maxWait="4000" username="username" password="password" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:portnum/dbname" validationQuery="SELECT 1" testOnBorrow="true" /> </Context>