gpt4 book ai didi

android - Sqlite异常,语法错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:17 25 4
gpt4 key购买 nike

我还在学习 Android 开发,我在创建 sqlite 数据库表时遇到了问题。这是我的代码的一部分:

`

private static final String CREATE_ADS_PICTURE = "CREATE TABLE "
+ AdsBDD.TABLE_ADS_PICTURE + "(" + AdsBDD.ID_PICS
+ " INTEGER PRIMARY KEY AUTOINCREMENT ," + AdsBDD.AD_ID
+ " INTEGER NOT NULL," + AdsBDD.PICTURE + " TEXT," + AdsBDD.FOLDER
+ " TEXT," + AdsBDD.ORDER_NO + " INTEGER NOT NULL);";

private static final String CREATE_AGENCES = "CREATE TABLE "
+ AgencesBDD.TABLE_AGENCES + "(" + AgencesBDD.ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + AgencesBDD.GROUP
+ " INTEGER," + AgencesBDD.USERNAME + " TEXT," + AgencesBDD.EMAIL
+ " TEXT," + AgencesBDD.CONTACT_NAME + " TEXT,"
+ AgencesBDD.REGISTRATION_DATE + " TEXT," + AgencesBDD.ACTIVATION
+ " TEXT," + AgencesBDD.ACTIVE + " INTEGER," + AgencesBDD.STORE
+ " INTEGER," + AgencesBDD.STORE_BANNER + " TEXT,"
+ AgencesBDD.RATING + " REAL," + AgencesBDD.LANGUAGE + " TEXT,"
+ AgencesBDD.IDENTITY + " TEXT," + AgencesBDD.ADDRESS + " TEXT,"
+ AgencesBDD.PHONE + " TEXT," + AgencesBDD.COMPANY + " TEXT,"
+ AgencesBDD.WEBPAGE + " TEXT," + AgencesBDD.CODE_POSTAL + " TEXT,"
+ AgencesBDD.JE_SUIS_UN + " TEXT," + AgencesBDD.VILLE + " TEXT,"
+ AgencesBDD.VIDEO + " TEXT);";

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_ADS_PICTURE);
db.execSQL(CREATE_AGENCES);
}



public class AgencesBDD {
public static final String TABLE_AGENCES = "agences";

public static final String ID = "id";
public static final String GROUP = "group";
public static final String USERNAME = "username";
public static final String EMAIL = "email";
public static final String CONTACT_NAME = "contact_name";
public static final String REGISTRATION_DATE = "registration_date";
public static final String ACTIVATION = "activation";
public static final String ACTIVE = "active";
public static final String STORE = "store";
public static final String STORE_BANNER = "store_banner";
public static final String RATING = "rating";
public static final String LANGUAGE = "language";
public static final String IDENTITY = "identity";
public static final String ADDRESS = "address";
public static final String PHONE = "phone";
public static final String COMPANY = "company";
public static final String WEBPAGE = "webpage";
public static final String CODE_POSTAL = "code_postal";
public static final String JE_SUIS_UN = "je_suis_un";
public static final String VILLE = "ville";
public static final String VIDEO = "video";

`所以问题是 Sqlite 为表 AGENCES 抛出了这个异常,但是表 AD_PICTURE 工作正常:

03-08 14:36:01.892: E/AndroidRuntime(10822): FATAL EXCEPTION: main
03-08 14:36:01.892: E/AndroidRuntime(10822): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infonetdiffusion.immohabitation/com.infonetdiffusion.immohabitation.FragmentBaseActivity}: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: CREATE TABLE agences(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,group INTEGER,username TEXT,email TEXT,contact_name TEXT,registration_date TEXT,activation TEXT,active INTEGER,store INTEGER,store_banner TEXT,rating REAL,language TEXT,identity TEXT,address TEXT,phone TEXT,company TEXT,webpage TEXT,code_postal TEXT,je_suis_un TEXT,ville TEXT,video TEXT);

它应该很容易修复,但我找不到我错在哪里......任何帮助将不胜感激!

最佳答案

您正在使用 sqlite 关键字作为列名,即 group sqliteKeyword这是限制

关于android - Sqlite异常,语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15295445/

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