No operations allowed after connection closed in JDBC

Source: Internet
Author: User


Organize from CSDN Forum, click here to see the original posts


The first call to this method is not a problem but the second time the following problem occurs (database-related operations, such as INSERT, query, etc.)

Com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException:
No operations allowed after connection closed

This problem how to solve AH only dao.close (), this closed connection method to remove, but it seems wrong ah.
Have you ever encountered a similar problem, there is a good solution.

Answer:

The reason is simple. Shutting down connections after the end of a database operation is the right thing to do, no big deal. As for the appearance: No operations allowed after connection closed. The reason for this problem is only one, you here and the database connection connection is a static, program sharing this one connection. So the first time on the database operation is not a problem, when the connection closed, the second time also want to operate the database connection certainly does not exist.


I am really this problem, I wrote connection static global, and then the first call after the direct shutdown, resulting in a global shutdown, as long as the connection as a local variable can be

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.