在SQLITE的字符串选择中使用WHERE?

时间:2014-02-26 09:24:31

标签: android sqlite

我需要你的帮助,请使用此代码..

我想搜索任何名称WHERE FIELD_CURRENCY = dollar 结果将只选择货币等于美元的名称。

    private static final String FIELD_ID = "_id";
private static final String FIELD_NAME = "name";
private static final String FIELD_FLAG = "flag";
private static final String FIELD_TEL = "tel";
private static final String FIELD_CURRENCY = "currency";
private static final String TABLE_NAME = "countries";

    /** Returns Countries */
public Cursor getCountries(String[] selectionArgs) {

    String selection = FIELD_NAME + " like ?";

    if (selectionArgs != null) {
        selectionArgs[0] = "%" + selectionArgs[0] + "%";

我的表:

   public class Country {

    // Array of strings storing country names
static String[] countries = new String[] { "India", "Pakistan",
        "Sri Lanka", "China", "test", "Nepal", "Taza",
        "Test", "test2", "Japan" };

// Array of integers points to images stored in /res/drawable
static int[] flags = new int[] { R.drawable.india, R.drawable.pakistan,
        R.drawable.japan, R.drawable.china, R.drawable.bangladesh,
        R.drawable.japan, R.drawable.afghanistan, R.drawable.japan,
        R.drawable.japan, R.drawable.japan  };

// Array of strings to store currencies
static String[] tel = new String[] { "0515155",
            "054545454", "045154", "0154645",
            "054685", "07700125", "0750",
            "07540", "07540", "07540" };

// Array of strings to store currencies
static String[] currency = new String[] { "Indian Rupee",
        "Pakistani Rupee", "Sri Lankan Rupee", "Renminbi",
        "dollar", "Nepalese Rupee", "Afghani",
        "dollar", "South Korean Won", "dollar"  };

}         } 我感谢你的帮助...

2 个答案:

答案 0 :(得分:0)

好吧,将它添加到您的选择中:

String selection = FIELD_NAME + " like ? AND " + FIELD_CURRENCY + "='dollar'";

答案 1 :(得分:0)

SELECT FROM FROM WHERE currency ='dollar'