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