开发者

Android database insert into specific row

开发者 https://www.devze.com 2023-04-01 09:37 出处:网络
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 m

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 .

0

精彩评论

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