我试图创建一个名为“知识”的表
以下是我的查询,
private static final String CREATE_KNOWLEDGE_STATUTORY = "CREATE TABLE " + TABLE_KNOWLEDGE_STATUTORY + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_STATUTORY_MAPPING + " TEXT,"
+ KEY_LOCATION + " TEXT,"
+ KEY_DESCRIPTION + " TEXT,"
+ KEY_ACTIVE + " TEXT,"
+ KEY_PROVISION + " TEXT,"
+ KEY_COMPLIANCE_TASK + " TEXT,"
+ KEY_FORMAT_FILE_LIST + " TEXT,"
+ KEY_DURATION + " TEXT,"
+ KEY_DOC_NAME + " TEXT,"
+ KEY_PENAL_CONSEQUENCE + " TEXT,"
+ KEY_DURATION_ID + " TEXT,"
+ KEY_FREQUENCY_ID + " INTEGER,"
+ KEY_REPEAT_FREQ + " TEXT,"
+ KEY_COMPLIANCE_ID + " INTEGER,"
+ KEY_REPEAT_TYPE_ID + " TEXT,"
+ KEY_STATUTORY_MONTH + " TEXT,"
+ KEY_STATUTORY_DATE + " TEXT,"
+ KEY_TRIGGER_DATE + " TEXT,"
+ KEY_REPEAT_BY + " TEXT" + ");";
以下是我用来创建它的方法,
public void addStatutory(StatutoryModel statutoryModel) {
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ID, statutoryModel.getId());
contentValues.put(KEY_STATUTORY_MAPPING, statutoryModel.getStatuoryMapping());
contentValues.put(KEY_LOCATION, statutoryModel.getLocation());
contentValues.put(KEY_DESCRIPTION, statutoryModel.getDescription());
contentValues.put(KEY_ACTIVE, statutoryModel.getIsStatutoryActive());
contentValues.put(KEY_PROVISION, statutoryModel.getStatutoryProvision());
contentValues.put(KEY_COMPLIANCE_TASK, statutoryModel.getComplianceTask());
contentValues.put(KEY_FORMAT_FILE_LIST, statutoryModel.getFormat_fileList());
contentValues.put(KEY_DURATION, statutoryModel.getDuration());
contentValues.put(KEY_DOC_NAME, statutoryModel.getDocument_name());
contentValues.put(KEY_PENAL_CONSEQUENCE, statutoryModel.getPenalConsequences());
contentValues.put(KEY_DURATION_ID, statutoryModel.getDurationType_id());
contentValues.put(KEY_FREQUENCY_ID, statutoryModel.getFrequencyId());
contentValues.put(KEY_REPEAT_FREQ, statutoryModel.getRepeatsEvery());
contentValues.put(KEY_COMPLIANCE_ID, statutoryModel.getComplianceId());
contentValues.put(KEY_REPEAT_TYPE_ID, statutoryModel.getRepeatsTypeId());
contentValues.put(KEY_STATUTORY_MONTH, statutoryModel.getStatutory_month());
contentValues.put(KEY_STATUTORY_DATE, statutoryModel.getStatutory_date());
contentValues.put(KEY_TRIGGER_DATE, statutoryModel.getTrigger_before_days());
contentValues.put(KEY_REPEAT_BY, statutoryModel.getRepeat_by());
sqLiteDatabase.insert(TABLE_KNOWLEDGE_STATUTORY,null,contentValues);
sqLiteDatabase.close();
}
我将其作为
调用DbHandler dbHandler = new DbHandler(getActivity());
dbHandler.addStatutory(new StatutoryModel(i, dbDesc, isStatutoryActive, statutoryProvision, complianceTask, format_fileList, duration, penalConsequences, document_name, durationType_id, frequencyId, repeatsEvery, repeatsTypeId, complianceId, statutory_month, statutory_date, trigger_before_days, repeat_by, compDescription, dbLoc));
问题是,我变得没有这样的表存在错误。以下是我的错误日志。
没有这样的表:知识03-28 15:58:48.584 28428-28428 /? E / SQLiteDatabase:插入repeatsEvery = null document_name = null时出错 location = India>>南法定准备=法定条款 2603161717 statutory_month = null statutoryMapping =合规性 描述2603161717 statutory_date = null repeatsTypeId = null duration = null frequencyId = 1 _id = 1 repeat_by = dayofmonth complianceId = 26 penalConsequences = complianceTask =合规性任务2603161717-1 trigger_before_days = null description = PRIMARY LEGISLATION 2503161026>>二级立法2603161717 format_fileList = null durationType_id = null isStatutoryActive = true android.database.sqlite.SQLiteException:没有这样的表:知识 (代码1):,编译时:INSERT INTO 知识(repeatsEvery,DOCUMENT_NAME,位置,statutoryProvision,statutory_month,statutoryMapping,statutory_date,repeatsTypeId,持续时间,frequencyId,_id,repeat_by,complianceId,penalConsequences,complianceTask,trigger_before_days介绍format_fileList,durationType_id,isStatutoryActive) 价值观(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) 在android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native 方法)
在任何情况下,这个问题都是重复的,因为它被CL标记为重复,因为问题不在onUpgrade中,而在于运行应用程序而不刷新以前的数据
答案 0 :(得分:0)
确保您是否通过调用db.execSQL(CREATE_KNOWLEDGE_STATUTORY)创建了表;在你的DbHandler类的onCreate()方法?
答案 1 :(得分:0)
嘿,我在表创建定义中发现了语法错误。
您必须在常量TABLE_KNOWLEDGE_STATUTORY之后添加一个额外的空格,以便将括号与表名分开。
您的表创建定义应类似于以下内容:
private static final String CREATE_KNOWLEDGE_STATUTORY = "CREATE TABLE " + TABLE_KNOWLEDGE_STATUTORY + " ("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_STATUTORY_MAPPING + " TEXT,"
+ KEY_LOCATION + " TEXT,"
+ KEY_DESCRIPTION + " TEXT,"
+ KEY_ACTIVE + " TEXT,"
+ KEY_PROVISION + " TEXT,"
+ KEY_COMPLIANCE_TASK + " TEXT,"
+ KEY_FORMAT_FILE_LIST + " TEXT,"
+ KEY_DURATION + " TEXT,"
+ KEY_DOC_NAME + " TEXT,"
+ KEY_PENAL_CONSEQUENCE + " TEXT,"
+ KEY_DURATION_ID + " TEXT,"
+ KEY_FREQUENCY_ID + " INTEGER,"
+ KEY_REPEAT_FREQ + " TEXT,"
+ KEY_COMPLIANCE_ID + " INTEGER,"
+ KEY_REPEAT_TYPE_ID + " TEXT,"
+ KEY_STATUTORY_MONTH + " TEXT,"
+ KEY_STATUTORY_DATE + " TEXT,"
+ KEY_TRIGGER_DATE + " TEXT,"
+ KEY_REPEAT_BY + " TEXT" + ");";
在表定义中,表未正确创建,因此当您尝试插入新记录时,显然会出现“无此表”错误。
答案 2 :(得分:-1)
我认为您没有发布正确的错误消息。这是您尝试插入时获得的错误,而不是失败的create table中的错误。你甚至在任何地方执行查询CREATE_KNOWLEDGE_STATUTORY
吗?
查看您的创建表,问题可能是最后的;
。从Java执行SQL时,不包括;
。我认为这会产生错误,例如“无效字符”。