开发者

Can't insert text into my SQLite database

开发者 https://www.devze.com 2023-01-26 02:50 出处:网络
I\'m trying to insert text into my SQLite database, but for some reason it doesn\'t work. It never executes..

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

精彩评论

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

关注公众号