Questions about single quotes, double quotes, and plus signs in SQL statements

Source: Internet
Author: User

The string data is enclosed in single quotation marks, and the + sign is used to concatenate the strings. Database fields are integral type of time do not add single quotation marks, is a string to add, other types according to the actual situation, the double quotation marks are used to stitch strings, single quotation marks are the inherent wording of SQL, because you want to be dynamic splicing, involving variables, so you want to use "+" to combine each string fragment. The end result is a SQL text that can be executed in the Database Query Analyzer.

String sql = "INSERT into student values (" + student.getid () + ", '"
+ student.getusername () + "'," + student.getage () + ", '"
+ student.getclassnumber () + "')";

Because ID and age are int, so no single quotes are added,

Your username is defined in the database as a varchar type, while a conditional query on a character type is added to the ' ' Number:
Select COUNT (*) from student where username= ' AAA '
So when writing query strings in the background, you have to write this:
String sql = "SELECT COUNT (*) from student where Username= '" "+username+" "
The query statement that is mapped to this is:
Select COUNT (*) from student where student= ' AAA ' is up.

Questions about single quotes, double quotes, and plus signs in SQL statements

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.