0

在我的代码中,有一个函数可以检索其中 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;
   }

日志猫

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'
4

2 回答 2

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 子句的条目。

于 2013-08-16T06:50:02.143 回答
0

用这个替换 if else 循环中的代码行

 mCursor= db.rawQuery("select * from countable where  countdesc='" + inputText + "' and countdate='" + datevalue+ "'", null);
于 2013-08-16T07:07:41.703 回答