Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7694491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:19:57+00:00 2026-05-31T21:19:57+00:00

I want to retrieve values from SQLite database in my Android application. Here in

  • 0

I want to retrieve values from SQLite database in my Android application. Here in my program first I stored two strings in to SQLite and my table name is ‘name’. In second part I retrieve two strings which were stored in the SQLite database and display them in edit text field. But after I run the program, it displays empty screen only. Please give me a solution or any changes in my code.

     package com.ret;

     import java.util.Locale;

     import android.app.Activity;
     import android.content.ContentValues;
     import android.content.Intent;
     import android.database.Cursor;
     import android.database.sqlite.SQLiteDatabase;
     import android.os.Bundle;
     import android.view.View;
     import android.widget.Button;
     import android.widget.EditText;
     import android.R.id;

     public class RetriveActivity extends Activity {
          ContentValues values= new ContentValues();
      SQLiteDatabase db;
      String first="android";
      String last="apps";
      String f,s;
         @Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     db=openOrCreateDatabase("test5.db",SQLiteDatabase.CREATE_IF_NECESSARY,null);

     db.setVersion(1);
     db.setLocale(Locale.getDefault());
     db.setLockingEnabled(true);
     final String table_create="CREATE TABLE name("+"column1 TEXT,"+"column2 TEXT);";
     db.execSQL(table_create);
     values.put("column1",first);
     values.put("column2",last);
     db.insert("name", null, values);
     Cursor c = db.query("name",null,null, null, null, null,null);
     while(c.moveToFirst())
     {
     f=c.getString(c.getColumnIndex("column1"));
     s=c.getString(c.getColumnIndex("column2"));
     db.close();
     }
     EditText e1=(EditText)findViewById(R.id.editText1);
     e1.setText(""+f+""+s);
     db.close();

     }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:19:59+00:00Added an answer on May 31, 2026 at 9:19 pm

    Please look at to this example, it shows how to retrieve data from sqlite database.

    package com.collabera.labs.sai.db;
    
    import java.util.ArrayList;
    
    import android.app.ListActivity;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteException;
    import android.os.Bundle;
    import android.util.Log;
    import android.widget.ArrayAdapter;
    
    public class CRUDonDB extends ListActivity {
    
        private final String SAMPLE_DB_NAME = "myFriendsDb";
        private final String SAMPLE_TABLE_NAME = "friends";
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
    
            ArrayList<String> results = new ArrayList<String>();
            SQLiteDatabase sampleDB = null;
    
            try {
                sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
    
                sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                        SAMPLE_TABLE_NAME +
                        " (LastName VARCHAR, FirstName VARCHAR," +
                        " Country VARCHAR, Age INT(3));");
    
                sampleDB.execSQL("INSERT INTO " +
                        SAMPLE_TABLE_NAME +
                        " Values ('Makam','Sai Geetha','India',25);");
                sampleDB.execSQL("INSERT INTO " +
                        SAMPLE_TABLE_NAME +
                        " Values ('Chittur','Raman','India',25);");
                sampleDB.execSQL("INSERT INTO " +
                        SAMPLE_TABLE_NAME +
                        " Values ('Solutions','Collabera','India',20);");
    
                Cursor c = sampleDB.rawQuery("SELECT FirstName, Age FROM " +
                        SAMPLE_TABLE_NAME +
                        " where Age > 10 LIMIT 5", null);
    
                if (c != null ) {
                    if  (c.moveToFirst()) {
                        do {
                            String firstName = c.getString(c.getColumnIndex("FirstName"));
                            int age = c.getInt(c.getColumnIndex("Age"));
                            results.add("" + firstName + ",Age: " + age);
                        }while (c.moveToNext());
                    } 
                }
    
                this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
    
            } catch (SQLiteException se ) {
                Log.e(getClass().getSimpleName(), "Could not create or Open the database");
            } finally {
                if (sampleDB != null) 
                    sampleDB.execSQL("DELETE FROM " + SAMPLE_TABLE_NAME);
                    sampleDB.close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i want to retrieve values from SQL database for xml tags using java
I want to retrieve a set of records from a database, do a rs.next()
I want to retrieve all records from one table when there are no matches
I made iPad application in which, I want to insert record into database table,
I want to retrieve k max values from each row in a numpy array.
I am using this code to retrieve the values I want from XML: IEnumerable<ForewordReview>
I am new to Python and WampServer . I want to retrieve values from
I want to retrieve multiples values from a field. the code I am using
I want to retrieve some values from my url and post them in a
i want retrieve route values from RouteTable, but it's null. can anybody help? public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.