Android-SQLite没有这样的列,传递的列被忽略
答案:字符串字段需要在其周围加上“”单引号 我一直收到“没有这样的列:值(代码1)”的消息,却不明白为什么 我试图用索引存储人员,这样我可以唯一地识别他们,并检索不需要作为json查询的更复杂的数据,为此,我使用Gson从对象转换为json 编辑了创建查询,以显示功能独特的函数强> 堆栈跟踪Android-SQLite没有这样的列,传递的列被忽略,android,sqlite,android-sqlite,sql-insert,Android,Sqlite,Android Sqlite,Sql Insert,答案:字符串字段需要在其周围加上“”单引号 我一直收到“没有这样的列:值(代码1)”的消息,却不明白为什么 我试图用索引存储人员,这样我可以唯一地识别他们,并检索不需要作为json查询的更复杂的数据,为此,我使用Gson从对象转换为json 编辑了创建查询,以显示功能独特的函数 堆栈跟踪 android.database.sqlite.SQLiteException: no such column: Hank (code 1): , while compiling: INSERT OR REPL
android.database.sqlite.SQLiteException: no such column: Hank (code 1): , while compiling: INSERT OR REPLACE INTO person (firstname,
lastname, zipcode, birthdate, json) VALUES (Hank,Hairy,8888HH,'06-01-1966','{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}')
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
android.database.sqlite.SQLiteException:没有这样的列:Hank(代码1):,编译时:INSERT或REPLACE INTO person(firstname,
lastname、zipcode、birthdate、json)值(Hank、Hairy、8888HH、'06-01-1966'、'{“事件”:“[]”、“《评论》:[]”、“《故事列表》:[]”、“favoriteFoods”:“切达”、“peperoni”:“千层面”})
位于android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法)
位于android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
位于android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
位于android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
位于android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58)
位于android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31)
位于android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
位于android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
我已经盯着教程比较了好几个小时了,我只是不知道哪里出了问题。似乎出于某种原因,我传递的列被忽略,而值被用作列。非常感谢您提供有关导致此错误的原因的任何帮助或解释。字符串需要用引号括起来:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO "+PERSON_TABLE_NAME+"
(firstname, lastname, zipcode, birthdate, json) VALUES
('"+person.getFirstname()+"','"+person.getLastName()+"','"+person.getZipcode()+",
'"+person.getBirthdate+"','"+person.getLifestoryJson()+"')");
不知何故,您确实包装了日期、生活经历,但没有包装firstname、lastname和zipcode。字符串需要用引号包装:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO "+PERSON_TABLE_NAME+"
(firstname, lastname, zipcode, birthdate, json) VALUES
('"+person.getFirstname()+"','"+person.getLastName()+"','"+person.getZipcode()+",
'"+person.getBirthdate+"','"+person.getLifestoryJson()+"')");
不知何故,您确实包装了日期、生活经历,但没有包装firstname、lastname和zipcode。字符串需要用引号包装:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO "+PERSON_TABLE_NAME+"
(firstname, lastname, zipcode, birthdate, json) VALUES
('"+person.getFirstname()+"','"+person.getLastName()+"','"+person.getZipcode()+",
'"+person.getBirthdate+"','"+person.getLifestoryJson()+"')");
不知何故,您确实包装了日期、生活经历,但没有包装firstname、lastname和zipcode。字符串需要用引号包装:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO "+PERSON_TABLE_NAME+"
(firstname, lastname, zipcode, birthdate, json) VALUES
('"+person.getFirstname()+"','"+person.getLastName()+"','"+person.getZipcode()+",
'"+person.getBirthdate+"','"+person.getLifestoryJson()+"')");
不知何故,您确实包装了日期、生活经历,但没有包装名字、姓氏和zipcode。我不知道这是否与您的问题有关,但对于SQLite,我相信允许的数据类型是: 整数、文本、BLOB、实数和数字 因此,CREATETABLE语句可能会导致一些问题 下面是一个不同的create table语句:
CREATE TABLE 'person_table_name' (
'id' INTEGER,
'first_name' TEXT,
'last_name' TEXT,
'zipcode' TEXT,
'birthdate' TEXT,
'json' TEXT,
PRIMARY KEY(id)
);
您的“创建唯一索引”可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
您的insert或replace into语句可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
我使用了“SQLite的DB浏览器”(创建DB和测试SQLite语句等的小程序)
以上所有语句均已成功执行
我认为,针对您的具体情况,您需要针对您的具体陈述更改以下内容:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO " +
PERSON_TABLE_NAME + "(firstname, lastname, zipcode, birthdate, json) +
VALUES ('" + person.getFirstname() + "','" + person.getLastName() + "','" + person.getZipcode() + "','" + person.getBirthdate + "','" + person.getLifestoryJson() + "')");
似乎person.getFirstName()和person.getLAstName()方法调用周围没有“(单引号)我不知道这是否与您的问题有关,但对于SQLite,我相信允许的数据类型是: 整数、文本、BLOB、实数和数字 因此,CREATETABLE语句可能会导致一些问题 下面是一个不同的create table语句:
CREATE TABLE 'person_table_name' (
'id' INTEGER,
'first_name' TEXT,
'last_name' TEXT,
'zipcode' TEXT,
'birthdate' TEXT,
'json' TEXT,
PRIMARY KEY(id)
);
您的“创建唯一索引”可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
您的insert或replace into语句可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
我使用了“SQLite的DB浏览器”(创建DB和测试SQLite语句等的小程序)
以上所有语句均已成功执行
我认为,针对您的具体情况,您需要针对您的具体陈述更改以下内容:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO " +
PERSON_TABLE_NAME + "(firstname, lastname, zipcode, birthdate, json) +
VALUES ('" + person.getFirstname() + "','" + person.getLastName() + "','" + person.getZipcode() + "','" + person.getBirthdate + "','" + person.getLifestoryJson() + "')");
似乎person.getFirstName()和person.getLAstName()方法调用周围没有“(单引号)我不知道这是否与您的问题有关,但对于SQLite,我相信允许的数据类型是: 整数、文本、BLOB、实数和数字 因此,CREATETABLE语句可能会导致一些问题 下面是一个不同的create table语句:
CREATE TABLE 'person_table_name' (
'id' INTEGER,
'first_name' TEXT,
'last_name' TEXT,
'zipcode' TEXT,
'birthdate' TEXT,
'json' TEXT,
PRIMARY KEY(id)
);
您的“创建唯一索引”可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
您的insert或replace into语句可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
我使用了“SQLite的DB浏览器”(创建DB和测试SQLite语句等的小程序)
以上所有语句均已成功执行
我认为,针对您的具体情况,您需要针对您的具体陈述更改以下内容:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO " +
PERSON_TABLE_NAME + "(firstname, lastname, zipcode, birthdate, json) +
VALUES ('" + person.getFirstname() + "','" + person.getLastName() + "','" + person.getZipcode() + "','" + person.getBirthdate + "','" + person.getLifestoryJson() + "')");
似乎person.getFirstName()和person.getLAstName()方法调用周围没有“(单引号)我不知道这是否与您的问题有关,但对于SQLite,我相信允许的数据类型是: 整数、文本、BLOB、实数和数字 因此,CREATETABLE语句可能会导致一些问题 下面是一个不同的create table语句:
CREATE TABLE 'person_table_name' (
'id' INTEGER,
'first_name' TEXT,
'last_name' TEXT,
'zipcode' TEXT,
'birthdate' TEXT,
'json' TEXT,
PRIMARY KEY(id)
);
您的“创建唯一索引”可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
您的insert或replace into语句可能会更改为:
CREATE UNIQUE INDEX
person_unique
ON
person_table_name (first_name, last_name, zipcode, birthdate);
INSERT OR REPLACE INTO
person_table_name (first_name, last_name, zipcode, birthdate, json)
VALUES (
'Hank',
'Hairy',
'8888HH',
'06-01-1966',
'{"events":"[]","comments":[],"storyList":[],"favoriteFoods":"cheddar","peperoni":"lasagna"}'
);
我使用了“SQLite的DB浏览器”(创建DB和测试SQLite语句等的小程序)
以上所有语句均已成功执行
我认为,针对您的具体情况,您需要针对您的具体陈述更改以下内容:
getWritableDatabase().execSQL("INSERT OR REPLACE INTO " +
PERSON_TABLE_NAME + "(firstname, lastname, zipcode, birthdate, json) +
VALUES ('" + person.getFirstname() + "','" + person.getLastName() + "','" + person.getZipcode() + "','" + person.getBirthdate + "','" + person.getLifestoryJson() + "')");
似乎person.getFirstName()和person.getLAstName()方法调用周围没有“(单引号)如果使用?占位符。@DerGolem为真,这样可读性更好。然而,我不想为OP重写所有内容:)啊,是的,我包装了它们,因为它们有很多空白,我现在就试试,尽快给你回复!另外,由于您已经在调用getWritab