multiple where子句失败 - 为不同的列值指定相同的字符串

时间:2013-08-16 06:40:03

标签: android database android-sqlite

在我的代码中有一个函数来检索countdesc = inputText和countdate = datevalue的行。但是countdesc和countdate都被指定为EditText。这里给出了logcat。请帮我找到错误。

public Cursor fetchEventByName(String inputText,String datevalue ) throws SQLException {
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor mCursor = null;
        if (inputText == null || inputText.length () == 0) {
        mCursor = db.query(DATABASE_TABLE, new String[] {KEY_ROWID,
                KEY_DESC, KEY_DATE, KEY_EVENT },
        null, null, null, null, null);
        }
        else {

             mCursor= db.rawQuery("select * from <countable> where  countdesc='" + inputText + "' and countdate='" + datevalue+ "'", null);
        }

        if (mCursor != null) {
        mCursor.moveToFirst();
        }
        return mCursor;
   }

logcat的

08-16 06:28:11.730: E/AndroidRuntime(2673): java.lang.RuntimeException: Unable to start activity ComponentInfo{example.events1/example.events1.Getclicker}: android.database.sqlite.SQLiteException: near "<": syntax error (code 1): , while compiling: select * from <countable> where  countdesc='Yalahanka' and countdate='Yalahanka'

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

    SQLiteDatabase db=openOrCreateDatabase("MYDB", MODE_PRIVATE, null);
    String table="myTbl";
    String whereClause = "Number = ? AND Name = ?";
    String[] whereArgs = new String[] { strNum };
 whereArgs[1] = new String[] { strNname };
    db.delete(table, whereClause, whereArgs);
    db.close();

在上面的代码中,我正在删除带有多个where子句的条目。

答案 1 :(得分:0)

使用此

替换if else循环中的代码行
 mCursor= db.rawQuery("select * from countable where  countdesc='" + inputText + "' and countdate='" + datevalue+ "'", null);