Answer the question
In order to leave comments, you need to log in
How to determine its id in a SQLite table knowing one string?
Let's say I have a table:
_id city music
1 London beatles
2 Moscow Joseph Kobzon
3 USA one republic
And I got the value London by intent.getextra. How can I find out the id of the table using only this value?
Answer the question
In order to leave comments, you need to log in
There is such a class - Cursor
It is used mainly for working with SQLite in Android. And there is also SQLiteOpenHelper They will help in working with the database.
In your case the request would be something like this
Cursor cursor = this.getReadableDatabase().query(tableName, null, "city =?", new String[]{city}, null, null, null); int[] arr = new int[cursor.getCount()];i=0; if(cursor.moveToFirst()){ int id= cursor.getColumnIndex("_id"); do { arr[i] = cursor.getInt(id)); i++; } while (cursor.moveToNext()); }
And if you google information on the designated classes, then for a start it will solve most of your questions.
Your question is very simple, I suspect that you just never worked with databases. Do not be lazy, read at least the basics of select, update, delete. And 80% of the questions will disappear.
SELECT ID FROM table_name WHERE City LIKE String In
general, I join the comments above, do not be lazy and spend at least a week (no jokes) studying the theory of databases like SQL. 1 time you will be helped, 2 times already buried.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question