简体   繁体   English

如何在Java中查询包含减号(-)的数据库表名称?

[英]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 我在数据库中有一个表名,称为(即): 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: 这是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. 我试过在table_name中添加引号...。但是不起作用。

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); 例如:“从[ARI5-v006]中选择*”-> bdd.rawQuery(“从[” + table_name +“]”中选择*,null);

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

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