I have a database and i can insert into it and read from it fine, but this is my issue:
first of all i have two tables, table1 and table2. Both tables only have 1 column and 1 row. So i didn't set my Key to autoincrement. Basically i want to keep overwriiting that value in the row and column instead of adding many values how do i do this?
private static final String DATABASE_CREATE_DATA = "create table table1 (_id integer primary key, " + "table1 text);";开发者_StackOverflow
private static final String DATABASE_CREATE_WIFI = "create table table2 (_id integer primary key, " + "table2 text);";
and my insert is:
db.insertOrThrow(DATABASE_TABLE1, null, value);
But for some reason this increments the key and adds many values where i just want to keep overwriting the first value.
Generally with SQL, you use UPDATE to change data in rows, and INSERT to create new ones. I never worked with SQLite, but I'd be surprised if there wasn't an update function beside that insert one.
Edit: Looking at the docs, replaceOrThrow might be just what you're looking for.
You would need to either do a rawQuery using a WHERE clause, or use db.update, see this post for reference.
What you actually want to do is an update .
精彩评论