Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在SQLite数据库查询中设置多选参数_Android_Sqlite_Multipleselection - Fatal编程技术网

Android 在SQLite数据库查询中设置多选参数

Android 在SQLite数据库查询中设置多选参数,android,sqlite,multipleselection,Android,Sqlite,Multipleselection,如何查询多个选择参数?例如,下面是如何格式化我的数据库 以下是我仅使用一个seletion参数搜索的代码: public Cursor getType(String type) throws SQLException { Cursor mCursor = db.query(true, DB_TABLE, new String[] { KEY_ROWID, KEY_ALCOHOL,

如何查询多个选择参数?例如,下面是如何格式化我的数据库

以下是我仅使用一个seletion参数搜索的代码:

public Cursor getType(String type) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DB_TABLE, new String[] {
                    KEY_ROWID,
                    KEY_ALCOHOL, 
                    KEY_TYPE,
                    KEY_BRAND,
                    KEY_PRICE
                    }, 
                    KEY_TYPE + "=?", 
                    new String[] { type },
                    null, 
                    null, 
                    null, 
                    null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
但这只按按键类型进行搜索,我如何设置它以便按按键类型、按键酒精和按键价格进行搜索?

这可能会对您有所帮助

  public Cursor getType(String type) throws SQLException 
    {
     Cursor mCursor =
        db.query(true, DB_TABLE, new String[] {
                KEY_ROWID,
                KEY_ALCOHOL, 
                KEY_TYPE,
                KEY_BRAND,
                KEY_PRICE
                }, 
                KEY_TYPE + "=?" + " AND " + KEY_ALCOHOL + "=?" " AND " + KEY_PRICE + "=?", 

                new String[] { type,alcohol,price },
                null, 
                null, 
                null, 
                null);
if (mCursor != null) {
    mCursor.moveToFirst();
 }
 return mCursor;
}

想出来了!!感谢@Rajendra给了我一些代码来构建!您只能将字符串添加到选择参数中,因此我执行了以下操作:

public Cursor getTest(String alcohol, String type, long price) throws SQLException 
{
    Cursor mCursor =
            myDataBase.query(true, DB_TABLE, new String[] {
                    KEY_ROWID,
                    KEY_ALCOHOL, 
                    KEY_TYPE,
                    KEY_BRAND,
                    KEY_PRICE
                    }, 
                    KEY_ALCOHOL + "=?" + " AND " + KEY_TYPE + "=?" + " AND " + KEY_PRICE + "<=" + price,
                    new String[] { alcohol, type},
                    null, 
                    null, 
                    null, 
                    null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}
public Cursor getTest(字符串酒精、字符串类型、长价格)抛出SQLException
{
光标mCursor=
myDataBase.query(true,DB_表,新字符串[]){
基尤·罗维德,
关键在于酒精,
按键式,
重点品牌,
关键价格
}, 

KEY_酒精+“=?”+”和“+KEY_TYPE+”=?“+”和“+KEY_PRICE+”唯一的问题是KEY_PRICE是一个int,所以我不能将int放入字符串[]。如果我尝试将PRICE作为字符串传递,它不会返回任何内容