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