Android SQLite SELECT Query

android sqlite select query with where clause
how to execute select query in sqlite android
update query in sqlite android
simple sqlite database example in android
sqlite insert query android
sqlite android studio
db.delete android
create table in sqlite android

I have taken String value from a EditText and set it inside SELECT QUERY after WHERE condition


TextView tv = (TextView) findViewById(;
EditTextet2 et = (EditText) findViewById(;

String name = et.getText().toString();

Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE name = '"+name+"'", null); 



But it doesn't work. Any suggestions?

Try trimming the string to make sure there is no extra white space:

Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE TRIM(name) = '"+name.trim()+"'", null);

Also use c.moveToFirst() like @thinksteep mentioned.

How to use SELECT Query in Android sqlite?, Before getting into example, we should know what sqlite data base in android is. SQLite is an opensource SQL database that stores data to a  Android SQLite SELECT Query. Ask Question Asked 8 years, 2 months ago. Active 1 year, 3 months ago. Android SQLite - Match multiword string. 0.

This is a complete code for select statements.

SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery("SELECT column1,column2,column3 FROM table ", null);
if (c.moveToFirst()){
    do {
        // Passing values 
        String column1 = c.getString(0);
        String column2 = c.getString(1);
        String column3 = c.getString(2); 
        // Do something Here with values
    } while(c.moveToNext());

SQLiteDatabase, Android SQLITE query selection example. In this example we are going to learn how to create a SQLite database adapter that will perform the basic operations  Android SQLITE query selection example In this example we are going to learn how to create a SQLite database adapter that will perform the basic operations such as creating the table, upgrading the database as well as providing access to the data based on given input parameters.

Try using the following statement:

Cursor c = db.rawQuery("SELECT * FROM tbl1 WHERE name = ?", new String[] {name});

Android requires that WHERE clauses compare to a ?, and you then specify an equal number of ? in the second parameter of the query (where you currently have null).

And as Nambari mentioned, you should use c.moveToFirst() rather than c.moveToNext()

Also, could there be quotations in name? That could screw things up as well.

Android SQLITE query selection , Take a look at the query [^] and rawQuery [^] documentation. The query methods and the parameter details are listed. You can alternatively  Select Query in SQLite and Android. Rate this: It will help more to understand about 'select query in android application' or android sqlite database.

Here is the below code.

String areaTyp = "SELECT " +AREA_TYPE + "  FROM "
            + AREA_TYPE_TABLE + " where `" + TYPE + "`="
            + id;

where id is the condition on which result will be displayed.

166 Android SQLite SELECT query Part 3 |, SQLite is an open-source social database i.e. used to perform database operations on android gadgets, for example, putting away, controlling  Select the rows using List & lt; & Gt; On Android sqlite Hi I need help with getting list of rows using a list values. I was wondering if i could have a search query using list of strings. If so, how should that be implemented? For example. I have these values inside my List<Info> info. Jan 10, 2015

 public User searchUser(String name) {
    User u = new User();
    SQLiteDatabase db = this.getWritableDatabase(); //get the database that was created in this instance
    Cursor c = db.rawQuery("select * from " + TABLE_NAME_User+" where username =?", new String[]{name});
    if (c.moveToLast()) {
        return u;

    }else {
        Log.e("error not found", "user can't be found or database empty");
        return u;


this is my code to select one user and one only so you initiate an empty object of your class then you call your writable Database use a cursor in case there many and you need one here you have a choice Use : 1-

   if (c.moveToLast()) { } //it return the last element in that cursor 

or Use : 2-

 if(c.moveToFirst()) {  } //return the first object in the cursor 

and don't forget in case the database is empty you'll have to deal with that in my case i just return an empty object

Good Luck

Select Query in SQLite and Android, This tutorial shows you how to use the simplest form of SQLite SELECT statement to query data from a single table. The SELECT clause is the main statement you use to query an SQLite database. In the SELECT clause, you state what to select. But before the select clause, let's see from where we can select data using the FROM clause. The FROM clause is used to specify where do you want to select data.

Android SQLite Database Tutorial (Select, Insert, Update, Delete), COLUMN_TIMESTAMP + " DESC"; SQLiteDatabase db = this.​getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null);  SQLite - SELECT Query SQLite SELECT statement is used to fetch the data from a SQLite database table which returns data in the form of a result table. These result tables are also called result sets.

SQLite SELECT - Querying Data From a Single Table, Queries can be created via the rawQuery() and query() methods. rawQuery() directly accepts an SQL select statement as input. query() provides a  SQLite Select Summary : in this tutorial, you will learn how to use SQLite SELECT statement to query data from a single table. The SELECT statement is one of the most commonly used statements in SQL. The SQLite SELECT statement provides all features of the SELECT statement in SQL standard.

Android SQLite Database Tutorial, Android SQLite Database Tutorial (Select, Insert, Update, Delete) August 10, 2016 Mithilesh Singh Android 38 SQLite is an open-source social database i.e. used to perform database operations on android gadgets, for example, putting away, controlling or recovering relentless information from the database.

  • print name and make sure you are getting valid name. use c.moveToFirst(); instead of and try.
  • This example is very bad and allows for SQL Injections. Why not use the second parameter correctly instead of inserting null?
  • Solved my problem.
  • Please note that using c.getString(c.getColumnIndex("column1")) is better than c.getString(0): you won't have to update indexes if you change your query.
  • I would also escape name parameter to avoid SQL injection
  • This has an SQL Injection Problem