1

当我尝试向 sqlite 数据库添加多行时发生错误。单排没有问题。此外,该应用程序因此在三星 Galaxy s2 上崩溃,但不是在 nexus 上。

下面是创建表的代码:

 private static final String DATABASE_CREATE = "create table "
        + TABLE_AWARDS + "(" + COLUMN_ID
        + " integer primary key autoincrement, " + COLUMN_TITLE
        + " text not null, " + COLUMN_DESCRIPTION + " text not null, "
        + COLUMN_TYPE + " integer not null, " + COLUMN_ACHIEVED
        + " integer not null " + ");";

以及将行插入表中的代码:

 private static final String DATABASE_INSERT = "INSERT into  awards (title, description, type, achieved) VALUES "
        + "('Speed maximum', 'Stay', 1 , 0),"
        + "('Speed maximum', 'under 130 km/h', 2 , 0);";

根据你给我的stackoverflow问题的答案,语法应该是:

private static final String DATABASE_INSERT = "INSERT into  'awards' "+
        "SELECT 'Speed maximum' AS 'title', 'under 150 km/h' AS 'description', 1 AS 'type', 0 AS 'achieved'"
            +" UNION SELECT 'Speed maximum', 'under 130 km/h', 2 , 0"
            +" UNION SELECT 'Speed maximum', 'under 100 km/h', 3 , 0";

但这也不起作用。

4

2 回答 2

0

在 Eclipse 中进入调试模式,在查询后放置一个断点,并在运行时查看 DATABASE_INSERT 之类的字符串的值,将其发布到此处,或者您可以在此处查看错误本身。

于 2013-01-09T12:17:38.237 回答
0
  1. Please try change the names of columns.
  2. To insert best solution is using insertOrThrow method (read in internet).
  3. Please give me your full code of class extensing SQLiteOpenHelper.
  4. Give logcat log please.
于 2013-01-09T12:24:13.543 回答