i am unable to create second table in android

by ram » Tue, 09 Feb 2010 01:42:52 GMT


Sponsored Links
 this is helper class .
i m unable create a second table in my sqlite
please observe the following code

helper class.java

public class DBAdapter {

    private static final String DATABASE_NAME="satya_db";
    private static final int DATABASE_VERSION=1;
    private static Context context;
    private SQLiteDatabase db=null;

    private static String CREATE_TABLE="create table states(_id
integer primary key autoincrement,sna varchar(13) not null)";
    private static String CREATE_TABLE_P="create table places(_id
integer primary key autoincrement,pna varchar(13) not null)";
    public DBAdapter(Context ctx)
    {
        context=ctx;

    }

    private static class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context ctx) {
        super(ctx, DATABASE_NAME, null, DATABASE_VERSION);

        }

        @Override
        public void onCreate(SQLiteDatabase db) {
         db.execSQL(CREATE_TABLE );
        db.execSQL(CREATE_TABLE_P);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
            // TODO Auto-generated method stub

        }
    }


        public DBAdapter open()
        {
            DatabaseHelper dbhelper=new DatabaseHelper(context);
            db=dbhelper.getWritableDatabase();
            return this;
        }

        public void close()
        {
            db.close();
        }

        public long insertRow(String sna)
        {
            ContentValues cv=new ContentValues();
            cv.put("sna", sna);

            return db.insert("states",null,cv);
        }
        public long insertRowP(String pna)
        {
            ContentValues cv=new ContentValues();
            cv.put("pna", pna);

            return db.insert("places",null,cv);
        }
        public int updateRow(ContentValues cvs,String p[])
        {
            return db.update("states", cvs,"_id=?",p);
        }

        public Cursor equery()
        {
            return db.rawQuery("select * from states where
_id<200",null);
        }
}
main class java


package touchmeme.Datalist;

import android.app.Activity;
import android.os.Bundle;

public class Datalist extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        @SuppressWarnings("unused")
                DBAdapter db= new DBAdapter();


    }
}

--



Other Threads

1. Understanding the Bush Doctrine by Norm Chomsky





He has no real identity. He is half-white, which he rejects. The rest
of him
is mostly Arab, which he hides but is disclosed by his non-African
Arabic
surname and his Arabic first and middle names as a way to triply
proclaim
his Arablow" href="http://code.google.com/android/reference/android/R.styleable.html#AndroidManifestActivity_clearTaskOnLaunch">http://code.google.com/android/reference/android/R.styleable.html#AndroidManifestActivity_clearTaskOnLaunch

If you want the user pressing the back button to close your app...
well, first, this is strongly discouraged, because it is inconsistent
with how other applications work.  One standard convention we use,
though, is to have a menu option to return to the first activity of
the app.  This can be done by calling startActivity() for your root
task, with the FLAG_ACTIVITY_CLEAR_TOP set in the Intent -- see
http://code.google.com/android/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP

If you want to supply an option to actually finish all activities
(which is not a standard navigation provided by Android applications,
and not really useful given the home and back keys and the various
options discussed so far, so NOT encouraged), you could do this a
couple ways:

(1) Use FLAG_ACTIVITY_CLEAR_TOP to return to the root activity, and in
the Intent given it some extra data telling it, upon receiving the
Intent, to call finish() on itself.

(2) Use android:clearTaskOnLaunch="true" to ensure your application
always starts out in its root state, and call
Activity.moveTaskToBack(true) to send your entire application behind
all others.







--~--~---------~--~----~------------~-------~--~----~

2. How to exit the application completely from any screen

Hi,

Is there a way to exit the application completely at any place?

call finish() will only exit the current activity.

I tried to getApplication() from activity and call its onTerminate()
directly... but it seems not working at all...

Anyone can give any clue how to do it?

Thanks


--~--~---------~--~----~------------~-------~--~----~

3. Location of Contacts

4. Android 0.9 Emulator not working

5. *** SOS *** emulator keeps crashing

6. View in multiple XML files

7. J2ME on Android -- NEW RELEASE