我在log cat中得到一个SQLite异常,说明" ANDcontraYesOrNo"附近存在语法错误。
Cursor c = db.query( VivzHelper.TABLE_NAME, columns, helper.TX_IDT+"
='"+name+"' AND" +helper.CONTRA_YES_OR_NO+ "='"+contraY+"'
OR"+helper.CONTRA_YES_OR_NO+"='"+contraN+"'" +"",null,null, null, NAME + "
ASC");
logcat的:
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near "ANDcontraYesOrNo":
syntax error (code 1): , while compiling: SELECT _id, name FROM outtable
WHERE txidt ='I' ANDcontraYesOrNo='Y' ORcontraYesOrNo='N' ORDER BY name ASC
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnect ion.java:893)
at
android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
答案 0 :(得分:2)
在AND
和OR
导致
Cursor c = db.query( VivzHelper.TABLE_NAME, columns, helper.TX_IDT+"
='"+name+"' AND " +helper.CONTRA_YES_OR_NO+ "='"+contraY+"'
OR "+helper.CONTRA_YES_OR_NO+"='"+contraN+"'" +"",null,null, null, NAME + "
ASC");