How to retrieve data from SQLite?

how to retrieve data from mysql database in android studio
how to retrieve data from sqlite database in android and display in custom listview
get data from sqlite android using cursor
sqlite query android
how to store data in sqlite database in android example
how to retrieve data from mysql database in android and display in textview
view data in sqlite database
read data from sqlite

I am working on an sqlite database in which I am sure that I have inserted in sqlite correctly. Now i am fetching data from sqlite using cursor but when I set the data to Texview, my application crashes. Here is my table: here is my db code:

SQLiteDatabase db = this.getReadableDatabase();
    String query = "SELECT * FROM " + PRODUCT_TABLE + " WHERE ID = 23";
    Cursor cursor = db.rawQuery(query,null);
    return cursor;

Here is my cursor code:

Cursor cursor = dbHelper.getCheckOutProduct(Id);
        if (cursor != null && cursor.getCount() > 0) {
            do {
                int proId = cursor.getInt(cursor.getColumnIndex("ID"));
                int addressId = cursor.getInt(cursor.getColumnIndex("Price"));
                int paymentTypeID = cursor.getInt(cursor.getColumnIndex("Quantity"));
                int customerID = cursor.getInt(cursor.getColumnIndex("ProductID"));
                Log.e("ProductId",String.valueOf(proId));
            }while (cursor.moveToNext());
        }

Where am I making a mistake?

     if (cursor != null && cursor.getCount() > 0) {
           cursor.moveToFirst();
                do {
                    int proId = cursor.getInt(cursor.getColumnIndex("ID"));
                    int addressId = cursor.getInt(cursor.getColumnIndex("Price"));
                    int paymentTypeID = cursor.getInt(cursor.getColumnIndex("Quantity"));
                    int customerID = cursor.getInt(cursor.getColumnIndex("ProductID"));
                    Log.e("ProductId",String.valueOf(proId));
                }while (cursor.moveToNext());
            }

Retrieve data | Sqlite database, Read operation in sqlite database in android studio. Buy me a coffee : https://​paypal.me/hariomagr.Duration: 3:45 Posted: Dec 10, 2017 eTour.com is the newest place to search, delivering top results from across the web. Content updated daily for data recovery.

SQLiteDatabase db = this.getReadableDatabase();
    String query = "SELECT * FROM " + PRODUCT_TABLE + " where id = 23";
    Cursor cursor = db.rawQuery(query,null);
    return cursor;

this is right query i guess

Android SQLite Tutorial - 3 - Retrieve data from database, How to insert information into the android database. Visit My blog : http://www.​easyway2in Duration: 20:59 Posted: Sep 2, 2014 Search for Data Recovery Data Here. Visit our Web Now!

Where are you storing the values retrieved form cursor? For easiness, you can create a model with required attributes and set it one by one, and return a list like this:

Cursor cursor = dbHelper.getCheckOutProduct(Id);
List<Model> values = new ArrayList<>();
    if (cursor != null && cursor.getCount() > 0) {
        do {
            int proId = cursor.getInt(cursor.getColumnIndex("ID"));
            int addressId = cursor.getInt(cursor.getColumnIndex("Price"));
            int paymentTypeID = cursor.getInt(cursor.getColumnIndex("Quantity"));
            int customerID = cursor.getInt(cursor.getColumnIndex("ProductID"));

            Model model = new Model();
            model.setProdId(prodId);
            //just like above line set other desired values.                
            values.add(model);
            Log.e("ProductId",String.valueOf(proId));
        }while (cursor.moveToNext());
    }

    return values;

Hope this helps to debug the problem.

How to retrieve data from sqlite database in android and display it in , on button click, first open the database, fetch the data and close the data base like this public class cytaty extends Activity { @Override protected void  You should use the asterisk (*) for the testing purpose only, not in the real application development. Because…. When you develop an application, you should control what SQLite returns to your application. Suppose, a table has 3 columns, and you use the asterisk (*) to retrieve the data from all three columns.

Retrieve data with SQLite queries, Once you've inserted data into a database table, the next thing you normally want to do is to retrieve and display the data. Using a new version  How to retrieve value from SQLite Database using Cursor query? SQLite is an open-source database that is used to store data. SQLite is a lightweight database that comes with Android OS. In the below code, we have used the rawQuery() which returns a cursor to retrieve value from the SQLite database through looping.

How to get Data From SQLite Database In Android, This tutorial explains step by step how we can get all data from SQLite database table and show it on your android. First of all we're going to  How to retrieve a specific rows from a sqlite preexisitng database in android Display result sqlite query in textview Displaying information from database in spinner, textview

Android - SQLite Database, We can move the cursor forward and retrieve the data. Cursor resultSet = mydatbase.rawQuery("Select * from TutorialsPoint",null); resultSet.moveToFirst(); String  To recover deleted data from a SQLite .db file, you can try this SQL Forensic Explorer utility. You can download the demo version from this link . You can even run a query to extract deleted data using the built-in SQL editor.

Comments
  • post your logcat.
  • i have uploaded snapshot that click on here in my exception
  • need to check Cursor.getCount()
  • Possible duplicate of CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
  • no, this code is different from the original: while(c.moveToNext()) {... will work but do {... will NOT
  • count is also greater than 0
  • Then you need to debug the column names
  • @ Kishan Singh ,you need to check row count which return from query