Overview
SQLite DataBase
- getWritableDataBase()
- getReadableDataBase()
- onCreate()
- onUpgrade()
Some query methods in SQLiteDataBase:
- execSQL()
- Insert()---------------ContentValues----------Put(String key,String value)
- Query()------Cursor------moveToFirst(),moveToNext(),getCount(),moveToPosition()
- update()
- delete()
Now there are some commands that need to be written in a Command Prompt to see the entries in the database.
The commands are as follows:
- set path of the bin
- set path of platform-tools
- adb shell
- cd data
- cd package name of the application
- cd databases
- pwd(present working directory)
- ls
- SQLite3 (name of database -db)
- table
- select * from table name;
Here are some snapshots of this.

The procedure of coding:
- Make an XML file activity_main.xml with two EditTexts and one Button.
- Just look them up in the MainActivity.java file
- Use another class named Mydatabase.java
- After that follow the commands as given above to see the entries in the database.
Code
MainActivity.java
- package com.example.sqlite;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.ContentValues;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends Activity implements OnClickListener
- {
- EditText euser, epass;
- Button inser;
- Mydatabase o1=new Mydatabase(this,"emp.db",null, 1);
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- euser=(EditText) findViewById(R.id.editText1);
- epass=(EditText) findViewById(R.id.editText2);
- inser=(Button) findViewById(R.id.button1);
- inser.setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(View v)
- {
- // TODO Auto-generated method stub
- add();
- }
- });
- }
- public void add()
- {
- SQLiteDatabase db=o1.getWritableDatabase();
- ContentValues cv=new ContentValues();
- cv.put(Mydatabase.user, euser.getText().toString());
- cv.put(Mydatabase.pass, epass.getText().toString());
- db.insert(Mydatabase.dtab, null, cv);
- Toast.makeText(getApplicationContext(), "hii", 1000).show();
- }
- @Override
- public void onClick(View v)
- {
- // TODO Auto-generated method stub
- }
- }
Mydatabse.java

Abhijeet SinghPosted May 11, 2014, 12:45 PM
thanks
tatenda kabikePosted Apr 10, 2014, 5:40 AM
Great tutorial keep it up!