简体   繁体   中英

How to do query on database table name containing the minus sign (-) in java?

I have a table name, inside a database, called (ie) : ARI5-v006

The minus sign appears to be a problem.

Here's the query code:

String table_name="ARI5-v006";
Cursor dataCount = bdd.rawQuery("select * from " + table_name, null);

It causes an error.

Here's the logcat:

Caused by: android.database.sqlite.SQLiteException: near "-": syntax error (code 1): , while compiling: select * from ARI5-v006

I've tried add quote to the table_name.... but not working.

Any idea?

You can:

  1. Change the table name and use '_' instead of '-'
  2. Try quoting the table name in square braces. Ex: "select * from [ARI5-v006]" --> bdd.rawQuery("select * from [" + table_name + "]", null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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