gpt4 book ai didi

java - 无法在android上的sqlite数据库中创建表

转载 作者:行者123 更新时间:2023-12-01 09:07:38 27 4
gpt4 key购买 nike

我无法创建表。显示数据库已创建,也可以插入行,但表未创建。

public class DatabaseOperations extends SQLiteOpenHelper {

public static final int Database_version = 2;

public static final String Tag = DatabaseOperations.class.getSimpleName();

private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TableData.TableInfo.TABLE_NAME + " (" +
TableData.TableInfo.USER_ID + " INTEGER PRIMARY KEY," +
TableData.TableInfo.USER_PASS +" TEXT "+ "," +
TableData.TableInfo.USER_EMAIL +" TEXT "+ ");";

public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null,Database_version);
Log.d("Tag", "Database created");
}

@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(SQL_CREATE_ENTRIES);
Log.d("Tag", "Table created");

}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

}

public void putInformation(DatabaseOperations drop, String name, String pass, String email) {
SQLiteDatabase SQ = drop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_ID, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
cv.put(TableData.TableInfo.USER_EMAIL, email);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
Log.d("Tag", "inert a row");
}

public Cursor getInformation(DatabaseOperations dop) {
SQLiteDatabase SQ = dop.getReadableDatabase();
String[] coloumns = {TableData.TableInfo.USER_ID, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL};
Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, coloumns, null, null, null, null, null);
return CR;
}
}

最佳答案

您在 CREATE TABLE 中的 USER_EMAILUSER_PASS 列之间缺少 ,

添加后,您可以卸载应用程序以重新创建数据库。 When is SQLiteOpenHelper onCreate() / onUpgrade() run?

关于java - 无法在android上的sqlite数据库中创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41139382/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com