0

我决定为我的应用添加第二个表。即使它与第一个表创建字符串几乎完全相同的设置,我也会不断收到语法错误。

private static final String BUDGET_TABLE = "budgets";
private static final String KEY_ROW_ID_BUDGET = "_id";
private static final String KEY_BUDGET_LIMIT = "limit";
private static final String KEY_BUDGET_CURRENT_AMOUNT = "current_amount";

此字符串在“限制”附近引发语法错误

private static final String BUDGET_CREATE =
        "create table "+ BUDGET_TABLE +" ( "+ KEY_ROW_ID_BUDGET+" integer primary key autoincrement, "
        + KEY_BUDGET_LIMIT+" text not null, "+ KEY_BUDGET_CURRENT_AMOUNT+" text);";


db.execSQL(BUDGET_CREATE);
4

1 回答 1

2

它很简单,您可以/不应该在创建表格时使用关键字。您正在使用limit无效的 as 列,因此它会给您运行时错误,我建议您将其更改为budget_limit类似下面的内容,然后重试。

private static final String BUDGET_TABLE = "budgets";
private static final String KEY_ROW_ID_BUDGET = "_id";
private static final String KEY_BUDGET_LIMIT = "budget_limit";
private static final String KEY_BUDGET_CURRENT_AMOUNT = "current_amount";

private static final String BUDGET_CREATE =
        "create table "+ BUDGET_TABLE +" ( "+ KEY_ROW_ID_BUDGET+" integer primary key autoincrement, "
        + KEY_BUDGET_LIMIT+" text not null, "+ KEY_BUDGET_CURRENT_AMOUNT+" text);";


db.execSQL(BUDGET_CREATE);
于 2012-11-06T03:05:25.183 回答