The Java.sql.SQLException:Already closed is present in the Tomcat DBCP based Jndi configuration

Source: Internet
Author: User


A recent observation of the production environment found a phenomenon, a period of time do not operate, and then re-operation, the first time the database connection will appear: Java.sql.SQLException:Already closed., as follows:




The data source was managed with the Tomcat DBCP based on the Jndi configuration, which was looked up as follows:


Reason:

You ' re probably running to the fact that MYSQL closes connections which has been open "too long".
Probably If you do the request to the server again, and you'll find that it works because the connection is reopened.


Workaround:

One-to-deal with the-is-to- add the following to your context.xml Resource:

validationquery= "SELECT 1" (based on MySQL)

validationquery= "Select 1 from Dual" (Oracle-based)


Price:

This causes a very cheap test query to always be run first; if the connection have been closed, this gets the failure, and
Then a new connection is opened.


Think of the original configuration with WebLogic jdbc Jndi There is a special configuration item to configure this test query, and it is careless to configure Tomcat: (


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.