我正在尝试将文本插入到我的SQLite数据库中,但由于某种原因它无效。它永远不会执行..
下面的代码(这是我正在调用的函数):
public void setInfo(final String tableName, final int id, final String title, final String time, final String content) {
final String sql = "INSERT INTO " + tableName + "("+DB_COLUMN_ID+", "+DB_COLUMN_TITLE+", "+DB_COLUMN_TIME+","+DB_COLUMN_CONTENT+")" +
" VALUES ('"+id+"', '"+title+"', '"+time+"','"+content+"";
final SQLiteStatement stmt = mDatabase.compileStatement(sql);
stmt.execute();
}
提前致谢!
答案 0 :(得分:2)
看起来你错过了最后的单引号和sql语句的右括号。此外,id是int类型,因此它根本不需要任何引号。我猜它应该读:
final String sql = "INSERT INTO " + tableName + "("+DB_COLUMN_ID+", "+DB_COLUMN_TITLE+", "+DB_COLUMN_TIME+","+DB_COLUMN_CONTENT+")" +
" VALUES ("+id+", '"+title+"', '"+time+"','"+content+"')";