Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6921437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:16:36+00:00 2026-05-27T10:16:36+00:00

i can’t add 2 column in my existing db. i read any topic on

  • 0

i can’t add 2 column in my existing db. i read any topic on the web but i can’t fix my problem. may i have a complete personalized answer to my problem?
naturally i don’t wanna lose existing record, just alter it!
i want to add 2 column (phone (integer), automex (text)) to my db created in this way..

package com.ozzem.mybirthdaylite;



import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class dbMyBirthday {

    SQLiteDatabase db;

    private Context mContext;

    private DbHelper mDbHelper;

     private static final String DB_NAME="dbmyBirthday";
     private static final int DB_VERSION=1;

     //costruttore crea anche il DbHelper
     public dbMyBirthday(Context ctx){
         mContext=ctx;
         mDbHelper=new DbHelper(ctx, DB_NAME, null, DB_VERSION);       
 }


     public void open(){  //il database su cui agiamo è leggibile/scrivibile
         db=mDbHelper.getWritableDatabase();

 }

 public void close(){ //chiudiamo il database su cui agiamo
         db.close();
 }



 public void deletePerson(int idDel){ //metodo per inserire i dati

     String where = "id = " + idDel;
     db.delete(Person.PERSON_TABLE, where,null);
//     Log.d("db_call", "Record of id["+idDel+"] deleted");

}


 public void insertPerson(long l,String name,String birthday){ //metodo per inserire i dati
         ContentValues cv=new ContentValues();
         cv.put(Person.UID, l);
         cv.put(Person.NAME, name);
         cv.put(Person.BIRTHDAY, birthday);

         db.insert(Person.PERSON_TABLE, null, cv);
//         Log.d("db_call", "Record of uid["+uid+"] insered");

 }

 public boolean exist(long uid){
     boolean ex = false;

     Cursor c= db.rawQuery("SELECT COUNT(*) FROM " + Person.PERSON_TABLE + " WHERE uid = "+ "'" + uid + "'", null);
        c.moveToFirst();
      int jcount = c.getInt(0);

      if (jcount >0){
        ex=true;            
    }
     return ex;
 }



 public void updatePersonFromId(int id,String name,String birthday){

     ContentValues cv=new ContentValues();
//   cv.put(Person.UID, id);
     cv.put(Person.NAME, name);
     cv.put(Person.BIRTHDAY, birthday);

     String where = "id = " + "'"+id+"'";
     db.update(Person.PERSON_TABLE, cv, where, null);
//     Log.d("db_call", "Record of id["+id+"] updated");

 }

 public void updatePersonFromUid(long l,String name,String birthday){

     ContentValues cv=new ContentValues();
     cv.put(Person.UID, l);
     cv.put(Person.NAME, name);
     cv.put(Person.BIRTHDAY, birthday);

     String where = "uid = " + "'"+l+"'";
     db.update(Person.PERSON_TABLE, cv, where, null);
//     Log.d("db_call", "Record of uid["+uid+"] updated");

 }

 public Cursor fetchAllBirthday(){ //metodo per fare la query di tutti i dati
//   Log.d("db_call", "Fetching all birthdays");    
     return db.query(Person.PERSON_TABLE, null,null,null,null,null,null);               
 }

 public static class Person {  // i metadati della tabella, accessibili ovunque

        static final String PERSON_TABLE = "person";
         static final String ID = "id";
         static final String UID = "uid";
         static final String NAME = "name";
         public static final String BIRTHDAY = "birthday";

 }

 private static final String PERSON_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS "  //codice sql di creazione della tabella

                + Person.PERSON_TABLE + " (" 
                 + Person.ID + " integer primary key autoincrement, "
                 + Person.NAME + " text not null, "
                 + Person.UID + " integer not null, "
                 + Person.BIRTHDAY + " text not null );";



     private class DbHelper extends SQLiteOpenHelper { //classe che ci aiuta nella creazione del db

         public DbHelper(Context context, String name, CursorFactory factory,int version) {
                 super(context, name, factory, version);
         }

    @Override
    public void onCreate(SQLiteDatabase _db) {
        // TODO Auto-generated method stub

         _db.execSQL(PERSON_TABLE_CREATE);


    }

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

    }

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:16:37+00:00Added an answer on May 27, 2026 at 10:16 am

    Increase DB_Version to 2 then in your OnUpgrade override of your OpenHelper run your upgrade code

    e.g:

        if (oldVersion==1 && newVersion==2) {
          db.execSQL("ALTER TABLE " + TableName + " ADD COLUMN " + ColumnName1);
          db.execSQL("ALTER TABLE " + TableName + " ADD COLUMN " + ColumnName2);
        }
    

    Also modify your inital code so that the new field is created at the same time as the table for those who do not have a version 1 database to upgrade. i.e Those who create a version 2 database first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can we add custom language for RecognizerIntent? I have search many SO Question like
I have a jquery bug and I've been looking for hours now, I can't
Can't figure out how to do this in a pretty way : I have
Can I set a maximum fps? Is there any way to limit fps in
Can you have submenus with the top level set to checkable in WPF? I
Can i get the source code for a WAMP stack installer somewhere? Any help
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
can any one tell me how can change this java code into objective c.is
can anyone help me in trying to check whether JavaScript is enabled in client
Can 2 or more equations defining a function in Haskell share the same where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.