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