我从我创建SQL查询的Activity中接收数据,但是我在字符串中遇到语法错误。谢谢你的帮助
String sql = "SELECT _Id,Date,cas,N,E,Altro FROM Ge WHERE Ea>0 AND cas LIKE "+c_ricevuta+" AND date LIKE '"+anno_ricevuto+"-%' ORDER BY data DESC";
此处语法错误:cas LIKE "+c_ricevuta+"
答案 0 :(得分:1)
c_ricevuta
应该是单引号''
:
String sql = "SELECT _Id,Date,cas,N,E,Altro FROM Ge WHERE Ea>0 AND cas LIKE '"+c_ricevuta+"' AND date LIKE '"+anno_ricevuto+"-%' ORDER BY data DESC";
请注意,在您的查询中使用字符串参数很容易出现语法错误和SQL注入。请查看?
字面占位符,例如query functions中的selectionArgs。
答案 1 :(得分:0)
以防万一,我在单词和“+”之间放置空格。另外,你没有使用引号来包围c_ricevuta