1

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);";
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.

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You would need to either do a rawQuery using a WHERE clause, or use db.update, see this post for reference.

Comments

0

What you actually want to do is an update .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.