-1

hi i am trying to make a raffle table but however i did created the database but no table is create, the run panel shows that i created it but the sqlite browser shows that there is nothing in it. here is the code: in the database java:

        public void onCreate(SQLiteDatabase db)
    {

        // Note the use of super, which calls the constructor of the SQLiteOpenHelper class,
        // which does the actual work of opening the database.
        Log.d(TAG, "DatabaseHelper onCreate");
        Log.d(TAG, RaffleTable.CREATE_STATEMENT);
        db.execSQL(RaffleTable.CREATE_STATEMENT);

    }

in the raffletalbe.java:

public class RaffleTable {

public static final String TABLE_NAME = "Raffle";

public static final String KEY_ID = "raffle_id";
public static final String KEY_NAME = "raffle_name";
public static final String KEY_PRICE = "price";
public static final String KEY_START = "raffle_start";
public static final String KEY_END = "raffle_end";
public static final String KEY_DESCRIPTION = "raffle_description";
public static final String KEY_TYPE = "raffle_type";
public static final String KEY_PRIZE = "raffle_prize";
public static final String KEY_LIMIT = "raffle_limit";

public static final String CREATE_STATEMENT = "CREATE TABLE "
        + TABLE_NAME
        + " (" + KEY_ID + " integer primary key autoincrement, "
        + KEY_NAME + " string not null, "
        + KEY_DESCRIPTION + " string, "
        + KEY_START + " string not null, "
        + KEY_END + " string not null, "
        + KEY_TYPE +  " integer not null, "
        + KEY_LIMIT + " integer, "
        + KEY_PRIZE + " String, "
        + KEY_PRICE + " real);";

what it shows in the run panel:

D/RaffleDatabase: DatabaseHelper onCreate
CREATE TABLE Raffle (raffle_id integer primary key autoincrement, raffle_name string not null, raffle_description string, raffle_start string not null, raffle_end string not null, raffle_type integer not null, raffle_limit integer, raffle_prize String, price real);

here is the code i used to insert the table:

        Raffle Ruffle1 = new Raffle();
    Ruffle1.setRuffleDes("742 Evergreen Terrace");
    Ruffle1.setRuffleEnd("20190102");
    Ruffle1.setRuffleStart("20190101");
    Ruffle1.setRuffleLimit(5);
    Ruffle1.setRuffleName("testing");
    Ruffle1.setRufflePrize("cooper");
    Ruffle1.setRuffleType("Normal");
    Ruffle1.setRufflePrice(1000);

    Raffle Ruffle2 = new Raffle();
    Ruffle2.setRuffleDes("742 Evergreen Terrace");
    Ruffle2.setRuffleEnd("20190102");
    Ruffle2.setRuffleStart("20190101");
    Ruffle2.setRuffleLimit(5);
    Ruffle2.setRuffleName("testing");
    Ruffle2.setRufflePrize("cooper");
    Ruffle2.setRuffleType("Normal");
    Ruffle2.setRufflePrice(1000);

    RaffleTable.insert(db, Ruffle1);
    RaffleTable.insert(db, Ruffle2);
  • Try to insert something in your table and let's see if it gives you any error or not. – Awais Ahmad May 31 '20 at 04:14
  • i have inserted something in it, no error occur but still nothing appears. – Utopia Chan May 31 '20 at 04:26
  • What database did you open in the browser? did you export the database from android studio device monitor? https://stackoverflow.com/questions/17529766/view-contents-of-database-file-in-android-studio – Sync it May 31 '20 at 04:36
  • There is nothing wrong with your code. You just need to put the updated file in your browser. May be your browser is reading the old file that's why you're not able to read the updated content – Awais Ahmad May 31 '20 at 05:00
  • hi, yes i exported that raffledatabase from the device monitor and tried to check if it successfully built the table but apparently not. – Utopia Chan May 31 '20 at 05:00
  • i did tried to delete the database and run again or update the version of the database, but it is still not working. – Utopia Chan May 31 '20 at 05:02

1 Answers1

0

There is nothing wrong with your code. You just need to put the updated file in your browser. May be your browser is reading the old file that's why you're not able to read the updated content.

Awais Ahmad
  • 427
  • 3
  • 17