Android 多个where子句失败-为不同的列值分配相同的字符串
在我的代码中,有一个函数用于检索countdesc=inputText和countdate=datevalue的行。但是countdesc和countdate都被指定为EditText。这里给出了日志。请帮助我查找错误Android 多个where子句失败-为不同的列值分配相同的字符串,android,database,android-sqlite,Android,Database,Android Sqlite,在我的代码中,有一个函数用于检索countdesc=inputText和countdate=datevalue的行。但是countdesc和countdate都被指定为EditText。这里给出了日志。请帮助我查找错误 public Cursor fetchEventByName(String inputText,String datevalue ) throws SQLException { SQLiteDatabase db = this.getReadableDatabas
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;
}
public Cursor fetchEventByName(字符串inputText,字符串datevalue)抛出SQLException{
SQLiteDatabase db=this.getReadableDatabase();
游标mCursor=null;
如果(inputText==null | | inputText.length()==0){
mCursor=db.query(数据库_表,新字符串[]{KEY_ROWID,
密钥描述,密钥日期,密钥事件},
空,空,空,空,空,空);
}
否则{
mCursor=db.rawQuery(“选择*其中countdesc='”+inputText+“'和countdate='”+datevalue+“'”,null);
}
if(mCursor!=null){
mCursor.moveToFirst();
}
返回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'
08-16 06:28:11.730:E/AndroidRuntime(2673):java.lang.RuntimeException:无法启动活动组件信息{example.events1/example.events1.Getclicker}:android.database.sqlite.SQLiteException:靠近“尝试以下代码:
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();
在上面的代码中,我正在删除带有multiple where子句的条目。将if-else循环中的代码行替换为
mCursor= db.rawQuery("select * from countable where countdesc='" + inputText + "' and countdate='" + datevalue+ "'", null);
从我在logcat中看到的情况来看,您只需要删除表名周围的<和>。您的查询应该像“select*From countable where countdesc=”……您可以发布整个日志cat吗@用户2681154