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 7693191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:01:38+00:00 2026-05-31T21:01:38+00:00

below code is my databasehandler class i got it from a tutorial. Beside that

  • 0

below code is my databasehandler class i got it from a tutorial. Beside that tutorial i saw this method in so many forums. However, even if i have create table it doesnt seems to be created. What is my wrong can so help me pls.

public class DatabaseHandler extends SQLiteOpenHelper implements
    DatabaseHandlerInterface {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "AACDroidDB";

// Contacts table name
private static final String TABLE_CONTACTS = "contacts";
private static final String TABLE_PHRASES = "phrase";

// Phrase Table Columns names
private static final String KEY_PHRASE_ID = "id";
private static final String KEY_PHRASE_STARTLETTER = "startLetter";
private static final String KEY_PHRASE_FULLPHRASE = "fullPhrase";
private static final String KEY_PHRASE_USAGECOUNT = "usageCount";
private static final String KEY_PHRASE_ISFAMOUS = "isFamous";
private static final String KEY_PHRASE_CREATEDATE = "createDate";
private static final String KEY_PHRASE_LASTUSAGEDATE = "lastUsageDate";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";

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

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {

    String CREATE_PHRASES_TABLE = "CREATE TABLE " + TABLE_PHRASES + "("
            + KEY_PHRASE_ID + " INTEGER PRIMARY KEY,"
            + KEY_PHRASE_STARTLETTER + " text, " 
            + KEY_PHRASE_FULLPHRASE + " text, " 
            + KEY_PHRASE_USAGECOUNT + " integer, "
            + KEY_PHRASE_ISFAMOUS + " integer, "
            + KEY_PHRASE_CREATEDATE + " text, " + KEY_PHRASE_LASTUSAGEDATE
            + " text" + ");";

    db.execSQL(CREATE_PHRASES_TABLE);
    Log.d(Constants.DB_LOG, "database created");
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_PHRASES);

    // Create tables again
    onCreate(db);
}

/**
 * All CRUD(Create, Read, Update, Delete) Operations
 */

// Adding new phrase
public void addPhrase(Phrase phrase) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(KEY_PHRASE_STARTLETTER, phrase.getStartletter());
    values.put(KEY_PHRASE_FULLPHRASE, phrase.getFullphrase());
    values.put(KEY_PHRASE_USAGECOUNT, phrase.getUsagecount());
    values.put(KEY_PHRASE_ISFAMOUS, phrase.getIsFamous());
    values.put(KEY_PHRASE_CREATEDATE, phrase.getCreateDate());
    values.put(KEY_PHRASE_LASTUSAGEDATE, phrase.getLastUsageDate());
    //
    db.insert(TABLE_PHRASES, null, values);
    db.close(); // Closing database connection
}

// getting new phrase
public Phrase getPhrase(int idForPhrase) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(TABLE_PHRASES, new String[] { KEY_PHRASE_ID,
            KEY_PHRASE_STARTLETTER, KEY_PHRASE_FULLPHRASE,
            // KEY_PHRASE_USAGECOUNT,
            KEY_PHRASE_ISFAMOUS,
            // KEY_PHRASE_CREATEDATE,
            KEY_PHRASE_LASTUSAGEDATE }, KEY_PHRASE_ID + "=?",
            new String[] { String.valueOf(idForPhrase) }, null, null, null,
            null);

    if (cursor != null)
        cursor.moveToFirst();

    // int id = Integer.parseInt(cursor.getString(0));
    String startLetter = cursor.getString(1);
    String fullPhrase = cursor.getString(2);
    // int usageCount = Integer.parseInt(cursor.getString(3));
    // int isFamous = Integer.parseInt(cursor.getString(4));
    // String createDate = cursor.getString(5);
    // String lastUsageDate = cursor.getString(6);

    Phrase phrase = new Phrase();
    // phrase.setId(id);
    phrase.setStartletter(startLetter);
    phrase.setFullphrase(fullPhrase);
    // phrase.setUsagecount(usageCount);
    // phrase.setIsFamous(isFamous);
    // phrase.setCreateDate(createDate);
    // phrase.setLastUsageDate(lastUsageDate);

    // return contact
    return phrase;
}

// Updating single contact
public int updatePhrase(Phrase phrase) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(KEY_PHRASE_STARTLETTER, phrase.getStartletter());
    values.put(KEY_PHRASE_FULLPHRASE, phrase.getFullphrase());
    values.put(KEY_PHRASE_USAGECOUNT, phrase.getUsagecount());
    values.put(KEY_PHRASE_ISFAMOUS, phrase.getIsFamous());
    values.put(KEY_PHRASE_CREATEDATE, phrase.getCreateDate());
    values.put(KEY_PHRASE_LASTUSAGEDATE, phrase.getLastUsageDate());

    // updating row
    return db.update(TABLE_PHRASES, values, KEY_PHRASE_ID + " = ?",
            new String[] { String.valueOf(phrase.getId()) });
}

}

  • 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-31T21:01:39+00:00Added an answer on May 31, 2026 at 9:01 pm

    The onCreate() method is only called when the database is first created on the device. Try clearing local data on the device from Settings -> Applications -> Manage applications

    You could also change the database version.

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

Sidebar

Related Questions

Below code gives this error message Specified method is not supported. But here is
The below code is taken from http://bonsaiden.github.com/JavaScript-Garden/ function Foo() { this.value = 42; }
This below code is forbidden in XHTML 1.1 strict mode: <form method=post action=index> <input
The below code is a factory class that is delivers objects of type IGraph
The below code in Java throws Null pointer exception. public class New{ int i;
The below code seems like it should work; however, the blob in the database
Below code is the response from the server: xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema><soap:Body><SendCardDetailsResponse xmlns=http://tempuri.org/><SendCardDetailsResult><ROOT xmlns=><DocumentElement><res-auth><auth-data count='1' ><**attribute
Below is code used to search a string where Identity= exists and stores that
The below code searches, copies & pastes the found data into another worksheet. However,
Below code works fine: <?php session_start(); $_SESSION['color'] = 'blue'; class utilities { public static

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.