简体   繁体   English

错误“; 预期”,sql语句

[英]error “ ; expected” ,sql statement

String l="UPDATE counselor SET firstName="qwe" WHERE id=1";

Could anyone tell me what's wrong with above statement,as q sql statement. 谁能告诉我上面的语句有什么问题,如q sql语句。 Netbeans displays as "; expected". Netbeans显示为“;预期”。 I can't understand why it isn't correct at least as a string. 我不明白为什么它至少作为字符串是不正确的。 Code is as follows. 代码如下。

String l="UPDATE counselor SET firstName="qwe" WHERE id=1";
Statement m=conn.createStatement();
ResultSet v=m.executeQuery(l);

In SQL, you should escape strings with ' . 在SQL中,应使用'字符串进行转义。 So, 所以,

String l="UPDATE counselor SET firstName='qwe' WHERE id=1";
String l="UPDATE counselor SET firstName=\"qwe\" WHERE id=1";

If you want to put quotes within quotes you must use the escape sequence, \\", on the interior quotes. To print the sentence. For example 如果要在引号内加上引号,则必须在内部引号上使用转义序列\\“。要打印句子。例如

She said "Hello!" to me.

you would write 你会写

System.out.println("She said \"Hello!\" to me.");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM