MySQL Breakfast Error

Works fine, go to bed, get up, all pages that contain database queries are broken. Related to breakfast? Tried skipping breakfast, and changing breakfast, without luck.

Problem is connections timing out (explained here). MySQL drops database connections after 8 hours by default.

For one thing, eek, put up an error page in the .jsps!

<%@ page errorPage="exceptionHandler.jsp">

Solution is described nicely here. Tell MySql to verify the connection before making a query. Add the code in red below to the database connection info in Tomcat’s context.xml:

<Resource name="jdbc/sakila" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="mysql" password="xxxxxx" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://ourfaircity:3306/sakila?autoReconnect=true" validationQuery="select 1" >

Update:  Well this solution only works for those applications that use Tomcat’s context.xml. Applications that establish the connection otherwise, such as Hibernate, should work with just the autoReconnect=true parameter added to the jdbc URL. We shall see.

Leave a comment

Your comment