当我尝试将多行添加到sqlite数据库时发生错误。单排没有问题。 此外,应用程序因此在三星Galaxy s2上崩溃,但不会在连接上崩溃。
下面是创建表格的代码:
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";
但这也不起作用。
答案 0 :(得分:0)
在eclipse中进入调试模式在查询之后设置一个断点并在运行时查看字符串的值,如DATABASE_INSERT,在此处发布或者您可以在其中看到错误。
答案 1 :(得分:0)