Q
Q
qqmthfck2015-08-12 20:17:03
Android
qqmthfck, 2015-08-12 20:17:03

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

4 answer(s)
D
Dante Faustoff, 2015-08-13
@qqmthfck

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.

E
Emin, 2015-08-12
@Ewintory

Make a query to the database by city name.

E
Evgeny Elchev, 2015-08-12
@rsi

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.

N
NullxWeight, 2015-08-14
@NullxWeight

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 question

Ask a Question

731 491 924 answers to any question