title: SQLite Database (why do this?)
body: <p>hi i am create a simple SQLite database in android.</p>
  
  <p>i use the SQLite helper class</p>
  
  <pre><code>package com.and.example.helper;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  import android.database.sqlite.SQLiteStatement;
  import android.util.Log;
  
  public class DatabaseHelper {
  
      private static final String DATABASE_NAME = "mydata10.db";
      private static final int DATABASE_VERSION = 1;
      private static final String TABLE_NAME = "mytable10";
  
      private SQLiteDatabase db;
      private Context context;
      private SQLiteStatement insertStm;
  
      private static final String INSERT = "insert into " + TABLE_NAME + "(name,latitude,longitude,address,contectno) values(?,?,?,?,?)";
  
  
      public DatabaseHelper (Context context) {
          this.context = context;
          OpenHelper openHelper = new OpenHelper(this.context);
          this.db = openHelper.getWritableDatabase();
          //db.execSQL("DROP TABLE IF EXISTS " +TABLE_NAME);
          this.insertStm = this.db.compileStatement(INSERT);
  
      }
  
      private static class OpenHelper extends SQLiteOpenHelper {
  
  
          public void onCreate(SQLiteDatabase db) {
  
              db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT, letitude REAL, longitude REAL, address TEXT, contectno INTEGER)" );
          }
  
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  
              Log.w("Example", "Upgrading database, this will drop table and recreate");
              db.execSQL("DROP TABLE IF EXISTS " +TABLE_NAME);
              onCreate(db);
          }
  
          public OpenHelper(Context context) {
              super(context, DATABASE_NAME, null, DATABASE_VERSION);
  
          }
      }
  
  
      public long insert(String name, double latitude, double longitude, String address, int contactno){
          this.insertStm.bindString(1, name);
          this.insertStm.bindDouble(2, latitude);
          this.insertStm.bindDouble(3, longitude);
          this.insertStm.bindString(4, address);
          this.insertStm.bindLong(5, contactno);
          return this.insertStm.executeInsert();
      }
  
      public void deleteAll(){
          this.db.delete(TABLE_NAME, null, null);
      }
  
      public List&lt;String&gt;selectAll(){
          List&lt;String&gt;list = new ArrayList&lt;String&gt;();
          Cursor cursor = this.db.query(TABLE_NAME, new String[]{"name","latitude","longitude","address","contectno"}, null, null, null, null, null);
  
          if(cursor.moveToFirst())
          {
              do {
                  list.add(cursor.getString(0));
                  list.add(cursor.getString(1));
                  list.add(cursor.getString(2));
                  list.add(cursor.getString(3));
                  list.add(cursor.getString(4));
  
              }while(cursor.moveToNext());
  
          }
          if(cursor != null &amp;&amp; !cursor.isClosed())
          {
              cursor.close();
          }
          return list;
      }
  }
  </code></pre>
  
  <p>My main Activity class</p>
  
  <pre><code>package com.and.example.database;
  
  import java.util.List;
  
  import com.and.example.helper.DatabaseHelper;
  
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.TextView;
  
  public class DatabaseDemoActivity extends Activity{
  
      private TextView textout;
      private DatabaseHelper sqlHelper;
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          textout = (TextView)findViewById(R.id.textview1);
  
          sqlHelper = new DatabaseHelper(this);
  
          sqlHelper.deleteAll();
  
          sqlHelper.insert("Durgesh",1.352566007,103.78921587,"ahmedabad",942974);
  //        sqlHelper.insert("Mukesh");
  
          List&lt;String&gt;names = this.sqlHelper.selectAll();
          StringBuilder sb = new StringBuilder();
          sb.append("Name in Database: \n");
          for(String name : names)
          {
              sb.append(name + "\n");
          }
  
          Log.d("Example", "name size - " +names.size());
          this.textout.setText(sb.toString());
      }
  }
  </code></pre>
  
  <p>and i run this project then generate a error Logcat</p>
  
  <p>03-08 09:16:57.963: ERROR/AndroidRuntime(1003): FATAL EXCEPTION: main
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.and.example.database/com.and.example.database.DatabaseDemoActivity}: android.database.sqlite.SQLiteException: table mytable10 has no column named latitude: , while compiling: insert into mytable10(name,latitude,longitude,address,contectno) values(?,?,?,?,?)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.os.Handler.dispatchMessage(Handler.java:99)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.os.Looper.loop(Looper.java:123)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at java.lang.reflect.Method.invoke(Method.java:521)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at dalvik.system.NativeStart.main(Native Method)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003): Caused by: android.database.sqlite.SQLiteException: table mytable10 has no column named latitude: , while compiling: insert into mytable10(name,latitude,longitude,address,contectno) values(?,?,?,?,?)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:36)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at com.and.example.helper.DatabaseHelper.(DatabaseHelper.java:31)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at com.and.example.database.DatabaseDemoActivity.onCreate(DatabaseDemoActivity.java:23)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  03-08 09:16:57.963: ERROR/AndroidRuntime(1003):     ... 11 more</p>
  
  <p>then i solve the error </p>
  
  <p>db.execSQL("CREATE TABLE " + TABLE_NAME + "(id INTEGER PRIMARY KEY, name TEXT, latitude REAL, longitude REAL, address TEXT, contectno INTEGER)" );</p>
  
  <p>and run the project but generate the same error in LogCat.</p>
  
  <p>and then i change the only database name and table name other code is same and successful run project.</p>
  
  <p>my Question is 
  Why do like this? </p>