Update/delete table contents from Android to mySQL

Asked 2 years ago, Updated 2 years ago, 42 views

How do I delete tables from mySQL DB on Android??

I don't know about SQL at all, so I'm only looking at Android books

Create DB, create table, add contents

What did you do with execSQL?

I don't know how to update (modify, update) or delete the contents...

I don't know how to do it. ㅠ<

Or if you can send me a related website, I'd appreciate it ㅠ<

mysql android

2022-09-22 22:07

2 Answers

If you have implemented DB creation, table creation, and insert, content updates and deletions are similar. You've implemented it using SQLite OpenHelper. You can do it like below.

Get objects from classes that inherit SQLiteOpenHelper (if you added DB creation, table creation, value, you will create classes that inherit SQLiteOpenHelper, so omit the code.)

For example, the object name is helper 

SQLiteDatabasedb = helper, getWritableDatabase(); //Get the db to update.

//Update column values
ContentValues values = new ContentValues();
values.put("carNumber", 1234); // When you want to change carNumber 
If db.update("table name", contentValues", "id=?", new String[] {id/*id is not string, insert String.valueOf(id).*/ }); The carNumber of the id you want to modify will change. (This is an example!))

//Value deletion is similar. 
db.delete('table name', 'id' + "=" + 1, null); //This will delete row with id 1

You can also send queries directly using the execSql method.

db.execSQL (String.format("DELETE FROM %s WHERE %s = %d", table name, column name, Integer.parseInt(Value)));

More detailed api can be found on the Android site .


2022-09-22 22:07

You can run it directly in SQL statement, but it would be convenient to use it like this.

http://developer.android.com/intl/ko/reference/android/database/sqlite/SQLiteDatabase.html


2022-09-22 22:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.