954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

i am unable to create second table in android

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();
 
        
    }
}

please help me
thanks

satyambnl
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

Why you not catching SQLException? There is possibility that execSQL() method is throwing one...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You