Q:

No operations allowed after connection closed on mysql

I changed host company for my webiste, in which I use a mySQL db.
From time to time I get this error:

No operations allowed after connection closed.

I remember I had the same problem the first time I run my site on the old server, and I fixed the problem with a "configuration fix" and not with a "code fix", but I don't remember what I did :(
I read mant posts here, but every talks about code fix and I don't think it's my case
Can someone help me?
Thank you
EDIT
I found this on my old context.xml file; probably this is the way I fixed the problem
  validationQuery="SELECT 1"
  testOnBorrow="true"

testOnBorrow: (boolean) The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false
validationQuery:(String) The SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query does not have to return any data, it just can't throw a SQLException. The default value is null. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server) 
Can someone confirm?

A:

You can use an autoReconnect=true parameter in your JDBC connection URL: (for example: "jdbc:mysql://localhost:3306/my-db?autoReconnect=true").
Note, though, that this can lead to problems if your application doesn't handle SQLExceptions properly.
From MySql documentation:

autoReconnect
Should the driver try to re-establish stale and/or dead connections? If > enabled the driver will throw an exception for a queries issued on a stale or dead connection, which belong to the current transaction, but will attempt reconnect before the next query issued on the connection in a new transaction. The use of this feature is not recommended, because it has side effects related to session state and data consistency when applications don't handle SQLExceptions properly, and is only designed to be used when you are unable to configure your application to handle SQLExceptions resulting from dead and stale connections properly. Alternatively, as a last option, investigate setting the MySQL server variable "wait_timeout" to a high value, rather than the default of 8 hours.

