简体   繁体   中英

SQLite is not creating any table in Android studio

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM