How to use SQLite in ANDROID, A really simple example.

By | August 23, 2012

Hello ANDROID Lovers……..

In today’s tutorial I will show you how to deal with SQLite Databases in ANDROID. You know that SQLite are Lightweight databases which is maintained only on the client side. They don’t need a server. The SQLite databases are simply a file wrapped around with some stuff which helps us deal with them like a normal database. And also don’t think they are like other databases like MySQL, Oracle etc, SQLite databases provide basic funtionalities to deal with a database.

Here I will show you how to use simple queries to deal with the SQLite database.
You may have found on the net numerous examples for SQLite in ANDROID using some extra classes which extend SQLiteOpenHelper classes which is pretty difficult to understand
But Don’t worry here I will show you how to deal with these databases like you normally do with your MYSQL Database or Oracle.

Before you need some resources.
1. An image “android.png” or “android.jpg” (which I am using as background for the layout).
OK that’s enough

=====================================================================================================================
Now go on and create a new project and name it “SQLiteExample.java” and drag and copy the following code to it.

SQLiteExample.java

package pac.SQLite;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class SQLiteExample extends Activity {

	LinearLayout Linear;
	SQLiteDatabase mydb;
	private static String DBNAME = "PERSONS.db";	// THIS IS THE SQLITE DATABASE FILE NAME.
	private static String TABLE = "MY_TABLE";		// THIS IS THE TABLE NAME

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Linear  = (LinearLayout)findViewById(R.id.linear);
        Toast.makeText(getApplicationContext(), "Creating table.", Toast.LENGTH_SHORT).show();

        dropTable();		// DROPPING THE TABLE.
        createTable();
        TextView t0 = new TextView(this);
    	t0.setText("This tutorial covers CREATION, INSERTION, UPDATION AND DELETION USING SQLITE DATABASES.                                                Creating table complete........");
    	Linear.addView(t0);
        Toast.makeText(getApplicationContext(), "Creating table complete.", Toast.LENGTH_SHORT).show();
        insertIntoTable();
        TextView t1 = new TextView(this);
    	t1.setText("Insert into table complete........");
    	Linear.addView(t1);
        Toast.makeText(getApplicationContext(), "Insert into table complete", Toast.LENGTH_SHORT).show();
        TextView t2 = new TextView(this);
    	t2.setText("Showing table values............");
    	Linear.addView(t2);
    	showTableValues();
        Toast.makeText(getApplicationContext(), "Showing table values", Toast.LENGTH_SHORT).show();
        updateTable();
        TextView t3 = new TextView(this);
    	t3.setText("Updating table values............");
    	Linear.addView(t3);
        Toast.makeText(getApplicationContext(), "Updating table values", Toast.LENGTH_SHORT).show();
        TextView t4 = new TextView(this);
    	t4.setText("Showing table values after updation..........");
    	Linear.addView(t4);
        Toast.makeText(getApplicationContext(), "Showing table values after updation.", Toast.LENGTH_SHORT).show();
        showTableValues();
        deleteValues();
        TextView t5 = new TextView(this);
    	t5.setText("Deleting table values..........");
    	Linear.addView(t5);
        Toast.makeText(getApplicationContext(), "Deleting table values", Toast.LENGTH_SHORT).show();
        TextView t6 = new TextView(this);
    	t6.setText("Showing table values after deletion.........");
    	Linear.addView(t6);
        Toast.makeText(getApplicationContext(), "Showing table values after deletion.", Toast.LENGTH_SHORT).show();
        showTableValues();
        setColor(t0);
        setColor(t1);
        setColor(t2);
        setColor(t3);
        setColor(t4);
        setColor(t5);
        setColor(t6);
    }
    // THIS FUNCTION SETS COLOR AND PADDING FOR THE TEXTVIEWS 
    public void setColor(TextView t){
    	t.setTextColor(Color.BLACK);
    	t.setPadding(20, 5, 0, 5);
    	t.setTextSize(1, 15);
    }

    // CREATE TABLE IF NOT EXISTS 
    public void createTable(){
    	try{
    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    	mydb.execSQL("CREATE TABLE IF  NOT EXISTS "+ TABLE +" (ID INTEGER PRIMARY KEY, NAME TEXT, PLACE TEXT);");
    	mydb.close();
    	}catch(Exception e){
    		Toast.makeText(getApplicationContext(), "Error in creating table", Toast.LENGTH_LONG);
    	}
    }
    // THIS FUNCTION INSERTS DATA TO THE DATABASE
    public void insertIntoTable(){
    	try{
	    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('CODERZHEAVEN','GREAT INDIA')");
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('ANTHONY','USA')");
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('SHUING','JAPAN')");
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('JAMES','INDIA')");
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('SOORYA','INDIA')");
	    	mydb.execSQL("INSERT INTO " + TABLE + "(NAME, PLACE) VALUES('MALIK','INDIA')");
	    	mydb.close();
	    }catch(Exception e){
			Toast.makeText(getApplicationContext(), "Error in inserting into table", Toast.LENGTH_LONG);
		}
    }
    // THIS FUNCTION SHOWS DATA FROM THE DATABASE 
    public void showTableValues(){
    	try{
	    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
	    	Cursor allrows  = mydb.rawQuery("SELECT * FROM "+  TABLE, null);
	    	System.out.println("COUNT : " + allrows.getCount());
	    	Integer cindex = allrows.getColumnIndex("NAME");
	    	Integer cindex1 = allrows.getColumnIndex("PLACE");

	    	TextView t = new TextView(this);
	    	t.setText("========================================");
			//Linear.removeAllViews();
			Linear.addView(t);

			if(allrows.moveToFirst()){
				do{
					LinearLayout id_row   = new LinearLayout(this);
					LinearLayout name_row = new LinearLayout(this);
					LinearLayout place_row= new LinearLayout(this);

					final TextView id_  = new TextView(this);
					final TextView name_ = new TextView(this);
					final TextView place_ = new TextView(this);
					final TextView   sep  = new TextView(this);

					String ID = allrows.getString(0);
			    	String NAME= allrows.getString(1);
			    	String PLACE= allrows.getString(2);

			    	id_.setTextColor(Color.RED);
			    	id_.setPadding(20, 5, 0, 5);
			    	name_.setTextColor(Color.RED);
			    	name_.setPadding(20, 5, 0, 5);
			    	place_.setTextColor(Color.RED);
			    	place_.setPadding(20, 5, 0, 5);

					System.out.println("NAME " + allrows.getString(cindex) + " PLACE : "+ allrows.getString(cindex1));
					System.out.println("ID : "+ ID  + " || NAME " + NAME + "|| PLACE : "+ PLACE);

					id_.setText("ID : " + ID);
					id_row.addView(id_);
					Linear.addView(id_row);
					name_.setText("NAME : "+NAME);
					name_row.addView(name_);
					Linear.addView(name_row);
					place_.setText("PLACE : " + PLACE);
					place_row.addView(place_);
					Linear.addView(place_row);
					sep.setText("---------------------------------------------------------------");
					Linear.addView(sep);
				}
				while(allrows.moveToNext());
			}
			mydb.close();
    	 }catch(Exception e){
 			Toast.makeText(getApplicationContext(), "Error encountered.", Toast.LENGTH_LONG);
 		}
	}
    // THIS FUNCTION UPDATES THE DATABASE ACCORDING TO THE CONDITION 
    public void updateTable(){
    	try{
	    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
	    	mydb.execSQL("UPDATE " + TABLE + " SET NAME = 'MAX' WHERE PLACE = 'USA'");
	    	mydb.close();
	    }catch(Exception e){
			Toast.makeText(getApplicationContext(), "Error encountered", Toast.LENGTH_LONG);
		}
    }
    // THIS FUNCTION DELETES VALUES FROM THE DATABASE ACCORDING TO THE CONDITION
    public void deleteValues(){
    	try{
	    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
	    	mydb.execSQL("DELETE FROM " + TABLE + " WHERE PLACE = 'USA'");
	    	mydb.close();
	    }catch(Exception e){
			Toast.makeText(getApplicationContext(), "Error encountered while deleting.", Toast.LENGTH_LONG);
		}
    }
    // THIS FUNTION DROPS A TABLE 
    public void dropTable(){
    	try{
	    	mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
	    	mydb.execSQL("DROP TABLE " + TABLE);
	    	mydb.close();
	    }catch(Exception e){
			Toast.makeText(getApplicationContext(), "Error encountered while dropping.", Toast.LENGTH_LONG);
		}
    }
}

Now the main.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
	<ScrollView
		android:id="@+id/ScrollView01"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"
		android:background="@drawable/android">
			<LinearLayout
				android:id="@+id/linear"
				android:orientation="vertical"
				android:layout_below="@+id/add_record"
				android:layout_width="wrap_content"
				android:layout_height="fill_parent">
			</LinearLayout>
	</ScrollView>
</LinearLayout>

The mainfest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="pac.SQLite"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SQLiteExample"
                  android:label="SQLite Example Demo">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

=====================================================================================================================

That’s all you are done go on and run the application.
Scroll Down to see different oprations done on the database.
Well if you want to see the database you can go to the DDMS Perspective and open File-Explorer and under folder “data/data/your-application-package/databases/”, there you will see the database.

However there is a way to see the actual database values like your MYSQL Database.
Check this post to see how its done.
SQLiteManager plugin for eclipse
Happy coding…

Fell free to leave your comments if you have any doubt on this.

if you want to use the android using php and mysql
please check these posts.

1. Android phpMysql connection
2. Android phpmySQL connection redone.

Check some other most popular and useful posts.

http://www.coderzheaven.com/2012/08/21/uploading-downloading-files-popular-posts/

37 thoughts on “How to use SQLite in ANDROID, A really simple example.

  1. Pingback: SQLiteManager plugin for eclipse | Coderz Heaven

  2. Pingback: learnSQL.99hosting.info » Blog Archive » Using SQLite in ANDROID, A really simple example. | Coderz Heaven

  3. CoDROID

    I’m trying to display the contents of a database in the form of a table, I’m just not able to figure my way out, to get to display the database.

    I did try:

    TableLayout table = (TableLayout) findViewById(R.id.tableLayout1);
    TableRow row = new TableRow(this);

    final TextView id_ = new TextView(this);
    final TextView name_ = new TextView(this);
    final TextView place_ = new TextView(this);
    final TextView date_ = new TextView(this);

    String ID = allrows.getString(0);
    String NAME= allrows.getString(1);
    String PLACE= allrows.getString(2);

    id_.setTextColor(Color.BLACK);
    id_.setPadding(20, 5, 0, 5);
    name_.setTextColor(Color.BLACK);
    name_.setPadding(20, 5, 0, 5);
    place_.setTextColor(Color.BLACK);
    place_.setPadding(20, 5, 0, 5);

    System.out.println(“NAME ” + allrows.getString(cindex) + ” PLACE : “+ allrows.getString(cindex1));
    System.out.println(“ID : “+ ID + ” || NAME ” + NAME + “|| PLACE : “+ PLACE);

    id_.setText(“ID : ” + ID);
    row.addView(id_);
    name_.setText(“NAME : “+NAME);
    row.addView(name_);
    place_.setText(“PLACE : ” + PLACE);
    row.addView(place_);
    table.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    Can you please help me on this one?

    Thanks in advance!

    Reply
  4. CoDROID

    I’m having difficulty in displaying the database in the form of a table.
    I can view the database that has been created and the database is all perfect!
    I am not able to display the fields like ID, Name, Place as column-headings and the corresponding data for each field as the rows of a table.

    Can you please help me on this one?

    Thanks!

    Reply
    1. James Post author

      Send us the code where you are getting the problem. We will check it out.

      Reply
  5. CoDROID

    This is how I tried to display the table by modifying your code:

    package pac.SQLite;

    import android.app.Activity;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.widget.TableLayout;
    import android.widget.TextView;
    import android.widget.Toast;

    public class SQLiteExample extends Activity {

    TableLayout Linear;
    SQLiteDatabase mydb;
    private static String DBNAME = “PERSONS.db”; // THIS IS THE SQLITE DATABASE FILE NAME.
    private static String TABLE = “MY_TABLE”; // THIS IS THE TABLE NAME

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Linear = (TableLayout)findViewById(R.id.linear);

    Toast.makeText(getApplicationContext(), “Creating table.”, Toast.LENGTH_LONG).show();

    dropTable(); // DROPPING THE TABLE.
    createTable();
    TextView t0 = new TextView(this);
    t0.setText(“Program for CREATION, INSERTION, UPDATION AND DELETION USING SQLITE DATABASES. n Creating table complete!”);
    Linear.addView(t0);
    Toast.makeText(getApplicationContext(), “Creating table complete.”, Toast.LENGTH_LONG).show();
    insertIntoTable();
    TextView t1 = new TextView(this);
    t1.setText(“Insert into table complete!”);
    Linear.addView(t1);
    Toast.makeText(getApplicationContext(), “Insert into table complete”, Toast.LENGTH_LONG).show();
    TextView t2 = new TextView(this);
    t2.setText(“Showing table values:”);
    Linear.addView(t2);
    showTableValues();
    Toast.makeText(getApplicationContext(), “Showing table values”, Toast.LENGTH_LONG).show();
    updateTable();
    TextView t3 = new TextView(this);
    t3.setText(“Updating table values!”);
    Linear.addView(t3);
    Toast.makeText(getApplicationContext(), “Updating table values”, Toast.LENGTH_LONG).show();
    TextView t4 = new TextView(this);
    t4.setText(“Showing table values after updation:”);
    Linear.addView(t4);
    Toast.makeText(getApplicationContext(), “Showing table values after updation.”, Toast.LENGTH_LONG).show();
    showTableValues();
    deleteValues();
    TextView t5 = new TextView(this);
    t5.setText(“Deleting table values!”);
    Linear.addView(t5);
    Toast.makeText(getApplicationContext(), “Deleting table values”, Toast.LENGTH_LONG).show();
    TextView t6 = new TextView(this);
    t6.setText(“Showing table values after deletion:”);
    Linear.addView(t6);
    Toast.makeText(getApplicationContext(), “Showing table values after deletion.”, Toast.LENGTH_LONG).show();
    showTableValues();

    setColor(t0);
    setColor(t1);
    setColor(t2);
    setColor(t3);
    setColor(t4);
    setColor(t5);
    setColor(t6);

    }

    /* THIS FUNCTION SETS COLOR AND PADDING FOR THE TEXTVIEWS */
    public void setColor(TextView t){
    t.setTextColor(Color.BLACK);
    t.setPadding(20, 5, 0, 5);
    t.setTextSize(1, 15);
    }

    /* CREATE TABLE IF NOT EXISTS */
    public void createTable(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    mydb.execSQL(“CREATE TABLE IF NOT EXISTS “+ TABLE +” (ID INTEGER PRIMARY KEY, NAME TEXT, PLACE TEXT, DATE BLOB);”);
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error in creating table”, Toast.LENGTH_LONG);
    }
    }
    /* THIS FUNCTION INSERTS DATA TO THE DATABASE */
    public void insertIntoTable(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘India Gate’,’INDIA’,datetime(‘now’,’localtime’))”);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘Eiffel Tower’,’FRANCE’,datetime(‘now’,’localtime’))”);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘Statue of Liberty’,’USA’,datetime(‘now’,’localtime’))”);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘Taj Mahal’,’INDIA’,datetime(‘now’,’localtime’))”);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘Great wall of China’,’CHINA’,datetime(‘now’,’localtime’))”);

    mydb.execSQL(“INSERT INTO ” + TABLE + “(NAME, PLACE, DATE) VALUES(‘Stonehenge’,’UK’,datetime(‘now’,’localtime’))”);
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error in inserting into table”, Toast.LENGTH_LONG);
    }
    }

    /* THIS FUNCTION SHOWS DATA FROM THE DATABASE */
    public void showTableValues(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    Cursor allrows = mydb.rawQuery(“SELECT * FROM “+ TABLE, null);
    System.out.println(“COUNT : ” + allrows.getCount());
    Integer cindex = allrows.getColumnIndex(“NAME”);
    Integer cindex1 = allrows.getColumnIndex(“PLACE”);
    Integer cindex2 = allrows.getColumnIndex(“DATE”);

    TextView t = new TextView(this);
    t.setText(“========================================”);

    Linear.addView(t);

    if(allrows.moveToFirst()){
    do{

    TableLayout id_row = new TableLayout(this);
    TableLayout name_row = new TableLayout(this);
    TableLayout place_row= new TableLayout(this);
    TableLayout date_row= new TableLayout(this);

    TextView id_ = (TextView) findViewById(R.id.id_);
    TextView name_ = (TextView) findViewById(R.id.name_);
    TextView place_ = (TextView) findViewById(R.id.place_);
    TextView date_ = (TextView) findViewById(R.id.date_);
    final TextView sep = new TextView(this);

    String ID = allrows.getString(0);
    String NAME= allrows.getString(1);
    String PLACE= allrows.getString(2);
    String DATE= allrows.getString(3);

    id_.setTextColor(Color.BLACK);
    id_.setPadding(20, 5, 0, 5);
    name_.setTextColor(Color.BLACK);
    name_.setPadding(20, 5, 0, 5);
    place_.setTextColor(Color.BLACK);
    place_.setPadding(20, 5, 0, 5);
    date_.setTextColor(Color.BLACK);
    date_.setPadding(20, 5, 0, 5);

    System.out.println(“NAME ” + allrows.getString(cindex) + ” PLACE : “+ allrows.getString(cindex1)+ ” DATE : “+ allrows.getString(cindex2));
    System.out.println(“ID : “+ ID + ” || NAME ” + NAME + “|| PLACE : “+ PLACE+ “|| DATE : “+ DATE);

    id_.setText(“” + ID);
    id_row.addView(id_);
    Linear.addView(id_row);
    name_.setText(“” + NAME);
    name_row.addView(name_);
    Linear.addView(name_row);
    place_.setText(“” + PLACE);
    place_row.addView(place_);
    Linear.addView(place_row);
    date_.setText(“” + DATE);
    date_row.addView(date_);
    Linear.addView(date_row);

    sep.setText(“—————————————————————“);
    Linear.addView(sep);
    }
    while(allrows.moveToNext());
    }
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error encountered.”, Toast.LENGTH_LONG);
    }
    }
    /* THIS FUNCTION UPDATES THE DATABASE ACCORDING TO THE CONDITION */
    public void updateTable(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    mydb.execSQL(“UPDATE ” + TABLE + ” SET NAME = ‘Machu Picchu’ WHERE PLACE = ‘UK'”);
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error encountered”, Toast.LENGTH_LONG);
    }
    }
    /* THIS FUNCTION DELETES VALUES FROM THE DATABASE ACCORDING TO THE CONDITION */
    public void deleteValues(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    mydb.execSQL(“DELETE FROM ” + TABLE + ” WHERE PLACE = ‘UK'”);
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error encountered while deleting.”, Toast.LENGTH_LONG);
    }
    }

    /* THIS FUNTION DROPS A TABLE */
    public void dropTable(){
    try{
    mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE,null);
    mydb.execSQL(“DROP TABLE ” + TABLE);
    mydb.close();
    }catch(Exception e){
    Toast.makeText(getApplicationContext(), “Error encountered while dropping.”, Toast.LENGTH_LONG);
    }
    }

    }

    Reply
  6. icloud9

    Hello sir i am new to android , at first u hav written thAt – [Before you need some resources.
    1. An image “android.png” or “android.jpg” (which I am using as background for the layout).
    OK that’s enough]

    where do i need to store this image?

    and i am getting 2 errors like
    setContentView(R.layout.main); – R cannot be resolved to a variable

    Linear = (LinearLayout)findViewById(R.id.linear);- R cannot be resolved to a variable

    Can u please help me out

    Reply
    1. James Post author

      Place these two images in the drawable folder. if you don’t have a drawable folder create one inside res and copy images with same name inside it.
      If you have no errors then “R’ will be resolved. Also make sure that you have the android target set. if not, right click on the your project folder and click properties and then android, set the target -> Apply -> ok
      Let me know if you got any errors then. Keep in touch. If u need more assistance join us on facebook and twitter.

      Reply
      1. jee123

        am getting the same error that R cannot be resolved and checked android target also. what i want to do remove this error

        Reply
  7. jettimadhu Chowdary

    Hi ,
    I did few changes to run this code..
    1. Change mydb.execSQL(“DROP TABLE” + TABLE); to mydb.execSQL(“DROP TABLE IF EXISTS ” + TABLE);
    2. Coming to Insert and other queries the “‘” appears as different. In eclipse It is not showing any error but the ‘ is diffeerent as it appears.
    Just Check it..

    Thanks

    Reply
    1. James Post author

      The ‘ is different because you copied the code from the webpage.

      Reply
  8. Mr Hunk

    This implementation is showing me sqlite error code 1 , mesg column not found error . Kindly tell me what to do in order to rectify this error .

    Reply
    1. James Post author

      @Mr Hunk :- You are trying to access a column that is not in the database. Please check the select query you have written. You may be accessing the column out of index. The index starts at 0 in the database.
      Also check that you typed the column name correctly.

      Reply
  9. niva

    Hello Sir i Created A new folder to paste the Android icon.

    Description Resource Path Location Type
    invalid resource directory name drawable-android /SQLite/res line 1 Android AAPT Problem

    How can i rectify this problem

    Reply
    1. James Post author

      Hello niva:- You cannot create a new folder inside res because that hierarchy is created by android itself. But you can rename your icon to which name you want and change the icon name in the manifest file.

      Reply
  10. Pingback: How to save score in Android Cocos2D? | Coderz Heaven

  11. Pingback: Working with SQLite databases through command Line in android … | Programmer Solution

  12. ramesh

    i actually gave two buttons in a layout and my intension is wen i click a button it should navigate to next layout displaying all the database values in that,which i am not getting. Can u pls help me out.

    Reply
  13. Kunal

    Hello,

    I am getting error in the line

    private

    The word span, class and private is being showed underlined red in eclipse.

    Please help me out. I am a newbie.

    Can you also explain to me what does this line do?

    Reply
    1. James Post author

      PLease remove that span tags, that’s not java code. that comes due to problem with the code syntax highlighter in this page.

      Reply
  14. Sam

    How we will upgrade the database using this simple code?

    Thanks in advance,
    Samir

    Reply
  15. aldaw hussien

    how to transfer file from sqlite table to another in android by(code)?

    Reply
    1. James Post author

      Save the file in the sdcard and save the path in the Sqlite, then when you go to another activity get the file path and read the file. Simple.

      Reply
  16. Thouseef

    Hi sir i’m new to android….
    i just want to know that… How to retrieve a value in editText box from SQLite..

    That is i want to retrieve a value from database which should be display in a editText box. Pls Help me sir….

    Reply
    1. James Post author

      This example actually shows you how to get values from the SQlite Database. Just do a setText with that values to your editText.

      Reply
  17. Pingback: [Help] Deleting Data from SQLite - Android Forums

  18. ana

    Thank you so much for the post…it is really worth …. Solved my problem 🙂 😀

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *