简体   繁体   English

SQLite语法错误在“?”附近

[英]Sqlite syntax error near “?”

Simple enough; 很简单; my code looks like this: 我的代码如下所示:

int idhash = getIdHash();
String[] args = {"runways", ""+idhash};
cursor = sqlite.rawQuery("SELECT * FROM ? WHERE idhash = ?", args);

And I see this line in logcat: 我在logcat中看到这一行:

E/SQLiteLog( 9570): (1) near "?": syntax error

Where did I go wrong? 我哪里做错了?

You can use ? 可以用? only for binding literals. 仅用于绑定文字。 You cannot use it for binding identifiers such as table names. 您不能将其用于绑定标识符,例如表名。 Identifiers must be in the SQL itself. 标识符必须在SQL本身中。

Maybe you can try 也许你可以尝试

  Cursor cursor =  sqlite.rawQuery("SELECT * FROM runways WHERE idhash = ?", new String[]{idhash.toString()});

and it 而且

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

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