我有一个从中运行查询的数据库。我得到了这个例外。我认为这与查询中的空间有关如何解决它。
FATAL EXCEPTION: main
E/AndroidRuntime( 2978): android.database.sqlite.SQLiteException: near "413": syntax error: , while compiling: SELECT DISTINCT _id, number, name, macid, type FROM favorites WHERE _id=(652) 413-6525
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
E/AndroidRuntime( 2978): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
E/AndroidRuntime( 2978): at com.honda.phone.DBAdapter.isPresent(DBAdapter.java:145)
E/AndroidRuntime( 2978): at com.honda.phone.FavoriteSelectionActivity.onClick(FavoriteSelectionActivity.java:226)
E/AndroidRuntime( 2978): at android.view.View.performClick(View.java:3511)
E/AndroidRuntime( 2978): at android.view.View$PerformClick.run(View.java:14105)
E/AndroidRuntime( 2978): at android.os.Handler.handleCallback(Handler.java:605)
E/AndroidRuntime( 2978): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 2978): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2978): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 2978): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2978): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2978): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 2978): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 2978): at dalvik.system.NativeStart.main(Native Method)
这是代码
public boolean isPresent(String number) throws SQLException
{
boolean returnValue = false;
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_NUMBER,
KEY_NAME,
KEY_MACID,
KEY_TYPE
},
KEY_ROWID + "=" + number,
null,
null,
null,
null,
null);
if (mCursor != null) {
if(mCursor.getCount() == 0){
returnValue = false;
}else{
returnValue = true;
mCursor.moveToFirst();
}
}
return returnValue;
}
我isPresent()
用包含(652) 413-6525
.