嗨,我正在尝试制作抽奖表,但是我确实创建了数据库,但没有创建表,运行面板显示我创建了它,但 sqlite 浏览器显示其中没有任何内容。 这是代码: 在数据库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);
}
在 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);";
运行面板中显示的内容:
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);
这是我用来插入表格的代码:
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);
最佳答案
你的代码没有任何问题。您只需将更新后的文件放入浏览器中即可。可能您的浏览器正在读取旧文件,这就是您无法读取更新内容的原因。
关于java - SQLite 没有在 Android studio 中创建任何表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62111417/