gpt4 book ai didi

java - 没有这样的表问题

转载 作者:行者123 更新时间:2023-12-01 14:54:37 27 4
gpt4 key购买 nike

我正在尝试查询数据库中第二个表的数据。

我能够插入数据库(或者被引导相信它是成功的)

我已经更改了版本号,但这似乎仍然有效。

有人能看到我在这里做错了什么吗?

目前我收到以下错误:

日志猫:

01-20 20:32:15.076: E/AndroidRuntime(303): FATAL EXCEPTION: main
01-20 20:32:15.076: E/AndroidRuntime(303): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.ViewAppointments}: android.database.sqlite.SQLiteException: no such table: appointmentTable: , while compiling: SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentTable ORDER BY app_name ASC
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.os.Looper.loop(Looper.java:123)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-20 20:32:15.076: E/AndroidRuntime(303): at java.lang.reflect.Method.invokeNative(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): at java.lang.reflect.Method.invoke(Method.java:521)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-20 20:32:15.076: E/AndroidRuntime(303): at dalvik.system.NativeStart.main(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): Caused by: android.database.sqlite.SQLiteException: no such table: appointmentTable: , while compiling: SELECT _id, app_name, app_type, app_time, app_date, app_comments FROM appointmentTable ORDER BY app_name ASC
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1301)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.example.flybase2.DBHandler.getAppointmentsData(DBHandler.java:325)
01-20 20:32:15.076: E/AndroidRuntime(303): at com.example.flybase2.ViewAppointments.onCreate(ViewAppointments.java:34)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-20 20:32:15.076: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

列变量:

    public static final String KEY_ROWAPPID = "_appid";
public static final String KEY_NAMEAPP = "app_name";
public static final String KEY_TYPEAPP = "app_type";
public static final String KEY_TIMEAPP = "app_time";
public static final String KEY_DATEAPP = "app_date";
public static final String KEY_COMMENTAPP = "app_comments";
public static final String KEY_ALARM = "app_alarm";

表名称和版本:

private static String DATABASE_TABLEAPP = "appointmentTable";
private static int DATABASE_VERSIONAPP = 1;

这是我的创建方法:

    @Override
public void onCreate(SQLiteDatabase db) {


db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_TEL + " TEXT NOT NULL, " +
KEY_EMAIL + " TEXT NOT NULL, " +
KEY_COMMENTS + " TEXT NOT NULL);"

);

db.execSQL("CREATE TABLE " + DATABASE_TABLEAPP + " (" +
KEY_ROWAPPID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAMEAPP + " TEXT NOT NULL, " +
KEY_TYPEAPP + " TEXT NOT NULL, " +
KEY_TIMEAPP + " TEXT NOT NULL, " +
KEY_DATEAPP + " TEXT NOT NULL, " +
KEY_COMMENTAPP + " TEXT NOT NULL, " +
KEY_ALARM + " BOOLEAN NOT NULL);"

);

升级时:

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

db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
onCreate(db);

db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLEAPP);
onCreate(db);
}

查询表的方法:

    public Cursor getAppointmentsData() {
String [] columns = new String[]{KEY_ROWAPPID, KEY_NAMEAPP, KEY_TYPEAPP, KEY_TIMEAPP, KEY_DATEAPP, KEY_COMMENTAPP};
Cursor c = ourDatabase.query(DATABASE_TABLEAPP, columns, null, null, null, null, KEY_NAMEAPP + " ASC", null);
return c;

最佳答案

删除第一个 onCreate( db ) 调用。

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

db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLEAPP);
onCreate(db);
}

关于java - 没有这样的表问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14429038/

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