JSP inserts data into database "Sqlserverexception: will truncate string or binary data" error resolution

Source: Internet
Author: User

recently in writing a small based JSP system development. Mastering the database has always felt good. But today there is a problem that bothers me for half a day. Then I was ready to go to bed, but I don't think we should solve this problem tonight. Then opened the computer, and began to churn. First go to the Internet to search for a bit of trouble. But most of the results can only be said: far to see and not solve my problem.

First, let me tell you about my situation: the data types and lengths in the database are basically appropriate. Create a new piece of data with SQL statements, no problem with leverage! But back to the JSP, submitting the form finally gave me a sad result. Repeated trial and failure, repeatedly failed to try. Result: "Sqlserverexception: Will truncate string or binary data". There's a lot of bugs down there. Look at me heartache!

The problem is that there is no problem in the database, and the problem occurs in the JSP code. Research for a long time, finally found: My database data design is gender for male or female. However, the form is selected because it is a radio button. So when you set the value, you don't notice the problem. Set it up as "girl" "Boy". The submission of course does not meet the data conditions!! A small problem plagued the day. But we can get a good night's sleep before the break, haha ~ ~

Summary: The reasons for these problems can be broadly considered in two directions: (1) The data field in the database setup problem, where the problem occurs, directly in the database test can be tested. You can then modify the length of the corresponding field. (2) Background code problem; In particular, when a constraint is set in a database, the code must render the same value as the constraint when it corresponds to the background code. Like radio buttons, multiple selection, pull down, and so on. This is the value you choose, not the value you fill in the text box directly, you can also see it. The choice is not necessarily the corresponding. So this needs to be noted.

JSP inserts data into database "Sqlserverexception: will truncate string or binary data" error resolution

Related Article

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.