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

  • SEARCH
  • Home
  • 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 8929403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:39:57+00:00 2026-06-15T08:39:57+00:00

I am making a database using a data handler class that extends SQL Lite

  • 0

I am making a database using a data handler class that extends SQL Lite open helper. I copied a example but this example only had three columns ID, name and skill. I am wanting to add three more columns Strength, Loyalty and Weapon. The code works with the three columns but as soon as I add in three more it doesn’t work and says it cannot find the new columns when creating the database. The code I am using is the following..

public class DatabaseHandler extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "Cards.db";

private static final String TABLE_NAME = "card";

private static final String COL_ID = "id";

private static final String COL_NAME = "name";

private static final String COL_SKILL = "skill";

private static final String COL_STRENGTH = "strength";

private static final String COL_LOYALTY = "loyalty";

private static final String COL_WEAPON = "weapon";

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
            + COL_ID + " INTEGER PRIMARY KEY," + COL_NAME + " TEXT,"
            + COL_SKILL + " TEXT" + 
            COL_STRENGTH + "TEXT" 
            + COL_LOYALTY + "TEXT" + COL_WEAPON + "TEXT"+
            ")";
    db.execSQL(CREATE_CONTACTS_TABLE);
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldNum, int newNum) {
    // Drop older table if exist and create fresh
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
}

public void addCard(Card card) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_ID, card.getID());
    values.put(COL_NAME, card.getName());
    values.put(COL_SKILL, card.getSkill());
    values.put(COL_STRENGTH, card.getStrength());
    values.put(COL_LOYALTY, card.getLoyalty());
    values.put(COL_WEAPON, card.getWeapon());
    db.insert(TABLE_NAME, null, values);
    db.close();
}

public List<Card> getAll() {
    List<Card> list = new ArrayList<Card>();
    String selectQuery = "SELECT  * FROM " + TABLE_NAME;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    if (cursor.moveToFirst()) {
        do {
            Card card = new Card(cursor.getInt(0),
                    cursor.getString(1), cursor.getString(2))
                    cursor.getString(3), cursor.getString(4),
                    cursor.getString(5)
                    );
            list.add(card);
        } while (cursor.moveToNext());
    }
    return list;
}

public void removeAll() {
    SQLiteDatabase db = this.getWritableDatabase();
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
}

public void deleteCard(Card card) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_NAME, COL_ID + " = ?",
            new String[] { String.valueOf(card.getID()) });
    db.close();
}

public int updateCard(Card card) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(COL_NAME, card.getName());
    values.put(COL_SKILL, card.getSkill());
    values.put(COL_STRENGTH, card.getStrength());
    values.put(COL_LOYALTY, card.getLoyalty());
    values.put(COL_WEAPON, card.getWeapon());
    return db.update(TABLE_NAME, values, COL_ID + " = ?",
            new String[] { String.valueOf(card.getID()) });
}

public Card getCard(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(TABLE_NAME, new String[] { COL_ID, COL_NAME,
            COL_SKILL, 
            COL_STRENGTH, COL_LOYALTY, COL_WEAPON 
            }, COL_ID + "=?",
            new String[] { String.valueOf(id) }, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
    }
    Card card = new Card(Integer.parseInt(cursor.getString(0)),
            cursor.getString(1), cursor.getString(2),
            cursor.getString(3), cursor.getString(4),
            cursor.getString(5)
            );
    return card;
}

}

I just can’t figure out when it doesn’t like the other columns I am trying to insert.

I also had a card class that looks like the following.

public class Card {

private int ID;

private String name;

private String skill;

private String strength; 

private String loyalty; 

private String weapon;


public Card(int ID, String name, String skill, String strength, String loyalty, String weapon) {
    this.ID = ID;
    this.name = name;
    this.strength = skill;
    this.skill = strength;
    this.loyalty = loyalty;
    this.weapon = weapon;
}

public String getName(){
    return this.name;
}

public void setName(String name){
    this.name = name;
}

public String getSkill(){
    return this.skill;
}

public void setSkill(String skill){
    this.skill = skill;
}

public String getStrength() {
    return this.strength;
}

public void setStrength(String strength) {
    this.strength = strength;
}

public String getLoyalty() {
    return this.loyalty;
}

public void setLoyalty(String loyalty) {
    this.loyalty = loyalty;
}

public String getWeapon() {
    return this.weapon;
}

public void setWeapon(String weapon) {
    this.weapon = weapon;
}

public int getID() {
    return ID;
}

public void setID(int iD) {
    ID = iD;
}

}

At the moment I am just testing the database works by writing it to the log in my browse class. The code I am using here is.

public class Browse extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout2);
    DatabaseHandler dh = new DatabaseHandler(this);

    Log.d("Database: ", "Dropping old table");
    dh.removeAll();

    Log.d("Database: ", "Inserting values..");
    dh.addCard(new Card(1, "Trevor", "11", "22", "33", "44"));
    dh.addCard(new Card(2, "Joseph", "49", "65", "87", "12"));
    dh.addCard(new Card(3, "Paul", "87", "12", "90", "01"));
    dh.addCard(new Card(4, "Mary", "30", "43", "12", "98"));

    Log.d("Database: ", "Listing all cards..");
    List<Card> list = dh.getAll();  
    for (Card lr : list) {
        String log = "ID:" + lr.getID() +" Name: " + lr.getName() + " Phone: " + lr.getSkill() + " Strength " + lr.getStrength()
                + " Loyalty: " + lr.getLoyalty() + " Weapon: " + lr.getWeapon();
        Log.d("Database: ", log); 
    }

    dh.deleteCard(new Card(1, "Trevor", "11", "22", "33", "44"));

    dh.updateCard(new Card(2, "Joseph", "36", "27", "87", "11"));

    Log.d("Database: ", "Re-listing all cards..");
    list = dh.getAll();
    for (Card lr : list) {
        String log = "ID:" + lr.getID() +" Name: " + lr.getName() + " Skill: " + lr.getSkill() + " Strength: " +lr.getStrength()
                + " Loyalty: " + lr.getLoyalty() + " Weapon: " + lr.getWeapon();
        Log.d("Database: ", log); 
    }

    Card retrieved = dh.getCard(3);
    Log.d("Database: ", "SINGLE: " + retrieved.getName());
}

}

Does anyone know why it won’t add the other columns? Thanks for any help given.

EDIT**

I am using all the code. It is when I run the application, I get the following in the Log Cat

11-30 12:44:19.193: I/Database(364): sqlite returned: error code = 1, msg = table card has no column named loyalty

11-30 12:44:19.213: E/Database(364): Error inserting id=1 loyalty=33 skill=11 strength=22 weapon=44 name=Trevor

11-30 12:44:19.213: E/Database(364): android.database.sqlite.SQLiteException: table card has no column named loyalty: , while compiling: INSERT INTO card(id, loyalty, skill, strength, weapon, name) VALUES(?, ?, ?, ?, ?, ?);

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:64)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:80)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:36)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)

11-30 12:44:19.213: E/Database(364): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)

11-30 12:44:19.213: E/Database(364): at uk.ac.tees.L1024329.DatabaseHandler.addCard(DatabaseHandler.java:96)

11-30 12:44:19.213: E/Database(364): at uk.ac.tees.L1024329.Browse.onCreate(Browse.java:22)

11-30 12:44:19.213: E/Database(364): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

11-30 12:44:19.213: E/Database(364): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

11-30 12:44:19.213: E/Database(364): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

11-30 12:44:19.213: E/Database(364): at android.app.ActivityThread.access$2300(ActivityThread.java:125)

11-30 12:44:19.213: E/Database(364): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

11-30 12:44:19.213: E/Database(364): at android.os.Handler.dispatchMessage(Handler.java:99)

11-30 12:44:19.213: E/Database(364): at android.os.Looper.loop(Looper.java:123)

11-30 12:44:19.213: E/Database(364): at android.app.ActivityThread.main(ActivityThread.java:4627)

11-30 12:44:19.213: E/Database(364): at java.lang.reflect.Method.invokeNative(Native Method)

11-30 12:44:19.213: E/Database(364): at java.lang.reflect.Method.invoke(Method.java:521)

11-30 12:44:19.213: E/Database(364): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

11-30 12:44:19.213: E/Database(364): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

11-30 12:44:19.213: E/Database(364): at dalvik.system.NativeStart.main(Native Method)

EDIT***

I have tried unistalling/ reinstalling the app and I have also tried clearing the data for the app but neither work.

  • 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-06-15T08:39:58+00:00Added an answer on June 15, 2026 at 8:39 am

    It looks as if you’ve missed out commas between the various column names. It should be

    @Override
    public void onCreate(SQLiteDatabase db) {
        String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_NAME + "("
                + COL_ID + " INTEGER PRIMARY KEY," + COL_NAME + " TEXT,"
                + COL_SKILL + " TEXT," + 
                COL_STRENGTH + " TEXT, " 
                + COL_LOYALTY + " TEXT, " + COL_WEAPON + " TEXT"+
                ")";
        db.execSQL(CREATE_CONTACTS_TABLE);
    }
    

    Hope this helps.

    UPDATE
    It’s also because you haven’t placed a space in between your column name variable and the column type, you would need to put a space before the word TEXT as in my amended code above.

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

Sidebar

Related Questions

I'm making application. I am using JQuery, that retrieves data from MySQL database using
I'm making an app that uses a SQLite database to store data. Sometimes my
I am making a app in Delphi 6 + MySQL database using standard data-aware
I'm making my own website using html and php, and a database using mysql
I'm making a simple task list app, and I'm using a database to hold
I am making changes on a website database I am developing using joomla 2.5
I'm making a dictionary database in SQLite and need some tips. My SQL is
wpdb class in wordpress is used for making connection to database. is there any
I have made a js function to remove data from a database using ajax.
I have a simple app that uses an SQL Express 2005 database. When the

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.