开发者

Can't insert text into my SQLite database

I'm trying to insert text into my SQLite database, but for some reason it doesn't work. It never executes..

Code below (this is my function that I'm calling):

public void setInfo(final String tableName, final int id, final String title, final String time, final String content) {

    final String sql = "INSERT INTO " + tableName + "("+D开发者_Go百科B_COLUMN_ID+", "+DB_COLUMN_TITLE+", "+DB_COLUMN_TIME+","+DB_COLUMN_CONTENT+")" + 
    " VALUES ('"+id+"', '"+title+"', '"+time+"','"+content+"";
    final SQLiteStatement stmt = mDatabase.compileStatement(sql); 
    stmt.execute();

} 

Thanks in advance!


Looks like you are missing the final single quote and the closing parenthesis on the sql statement. Also the id is type int so it doesn't need any quotes at all. I'm guessing it should read:

final String sql = "INSERT INTO " + tableName + "("+DB_COLUMN_ID+", "+DB_COLUMN_TITLE+", "+DB_COLUMN_TIME+","+DB_COLUMN_CONTENT+")" + 
    " VALUES ("+id+", '"+title+"', '"+time+"','"+content+"')";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜