当我尝试从数据库中删除时,我收到无法识别的令牌异常
我试图将我的字符串包含在''
而不是""
中,我尝试将值存储在专用的字符串变量中,而不是任何内容。
我只是不知道该怎么做,这是目前的代码:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
mDatabase.delete(CrimeTable.NAME,
values.getAsString(CrimeTable.Cols.UUID) + "= ?",
new String[]{crime.getId().toString()});
}
我也是这样尝试过的:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
mDatabase.delete(CrimeTable.NAME,
values.getAsString(CrimeTable.Cols.UUID) + "= " + crime.getId().toString(),
null);
}
而且:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
String databaseId = values.getAsString(CrimeTable.Cols.UUID);
String crimeId = crime.getId().toString();
mDatabase.delete(CrimeTable.NAME,
databaseId + "= ?",
new String[]{crimeId});
}
和
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
String databaseId = values.getAsString(CrimeTable.Cols.UUID);
String crimeId = crime.getId().toString();
mDatabase.delete(CrimeTable.NAME,
databaseId + "= " + crimeId,
null);
}
将''
和" "
应用于字符串的所有组合和排列...
即使我没有将它们解析为字符串并在其上使用''
或""
,我也总是会遇到相同的错误(来自此帖子中的前4个代码):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 27841
android.database.sqlite.SQLiteException: unrecognized token: "46cf" (code 1): , while compiling: DELETE FROM crimes WHERE fe950f06-dd38-46cf-898e-f4a7f7f27dab = fe950f06-dd38-46cf-898e-f4a7f7f27dab
如果我在我的数据库中尝试另一行:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 28258
android.database.sqlite.SQLiteException: no such column: b09902bc (code 1): , while compiling: DELETE FROM crimes WHERE b09902bc-0829-4989-8395-ed24dc397a85 = b09902bc-0829-4989-8395-ed24dc397a85
和...
public void deleteCrime(Crime crime) {
mDatabase.delete(CrimeTable.NAME,
CrimeTable.Cols.UUID + "=? ",
new String[]{crime.getId().toString()});
}
或者(从这篇文章中的最后一个代码开始,带有And ...):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 3418
android.database.sqlite.SQLiteException: unrecognized token: "46cf" (code 1): , while compiling: DELETE FROM crimes WHERE uuid= fe950f06-dd38-46cf-898e-f4a7f7f27dab
我不知道该怎么做......我很绝望,请帮助我!
答案 0 :(得分:1)
请尝试使用此代码:
public void deleteCrime(Crime crime)
{
mDatabase.execSQL("DELETE FROM crimes WHERE uuid = ?", new String([] {crime.getId()}));
}