Spit Groove MySQL Database jdbc operation, varchar type placeholder problem-single quote Commit

Source: Internet
Author: User

Not writing code for a long time. The ability to do a lot of the usual errors or frequent occurrences, vomiting blood today.

Simple pits always have to jump a few times to be reconciled. Very clear remember when the university in this pit almost suffocated, and now jumped into this hole, engaged in a long time finally know where the wrong.

= "insert into Cryptcontent (content,assistentcontent) value ('asf',  'asfd') ";D bhelper.insertquery (sqlString);

This operation is possible. Therefore the placeholder should also be fine, assuming that the placeholder is used correctly. The code is as follows (wrong):

= String.Format (                "insert into cryptcontent (content,assistentcontent)" Value (% s,%s) ",                assistantencryptresultstring, valuestring);        Dbhelper.insertquery (sqlString);

At this time how to debug all error, and then debug, error is as follows:
 Com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Unknown column ' Afsdf ' in ' Field list '

Debug Debug appears: INSERT into Cryptcontent (content,assistentcontent) value (AFSDF,ASFASFD)

Error found: Note that the field value of the varchar type column in the following value does not have single quotation marks. So FIX:

= String.Format (                "insert into Cryptcontent (content,assistentcontent) value ('  %s','%s'),                assistantencryptresultstring, valuestring);        
Dbhelper.insertquery (sqlString);

Then the execution succeeds.

use of Java string Formatting-string.format ()

Spit Groove MySQL Database jdbc operation, varchar type placeholder problem-single quote Commit

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.