Java does not capture hand-thrown errors inside stored procedures

Source: Internet
Author: User

Using the spring JdbcTemplate to manipulate additions and deletions, Basedao executes the stored procedure as follows:

This method either returns a true or throws an exception;

Phenomenon:

When the project is published in Tomcat, the same code, the same process, before testing this method, you can capture the process of manually thrown errors, after a period of time to test today, found that the process was not caught manually thrown error, and this method directly returned true! Pit Daddy

Check Data debugging:

1: The current process does not have set NOCOUNT on;

2: In the process of manual throw error RAISERROR before, if there is an INSERT statement, Tomcat may not catch this hand throw error, but in the case without set NOCOUNT on, put RAISERROR in front of the insert, you can capture.

Solve:

In Create PROCEDURE ..... As the following line, write:

SET NOCOUNT on

Conclusion:

Without set NOCOUNT ON, the process is no problem in WebSphere projects, but there may be problems in Tomcat, and Tomcat does not have many fault-tolerant mechanisms like websphere;

Why is the same code, process, can be captured before, and now cannot be captured? Because this time the database is restored, and the backup is a database backup of the production environment in the field, guess should be related to the database environment, the specific unknown, in short, directly add SET NOCOUNT on to the process, in Tomcat JDBC can normally capture the

Java does not capture hand-thrown errors inside stored procedures

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.