如何从数据库SQLite Java中检索多个数据(行)

时间:2013-12-28 04:29:08

标签: java android sqlite mobile-application

这就是我现在所做的。

我的表是这样的:

JAPANESEALPHA            ENGLISH          JAPANESECHAR
kiro                     kilo            \u30ad\u30ed
guramu                   gram            \u30b0\u30e9\u30e0
migi                     right           \u307f\u304e
mijikai                  short           \u307f\u3058\u304b\u3044

内部数据库(示例):

mDbHelper.createCrv("kiro","kilo","\u30ad\u30ed");
mDbHelper.createCrv("guramu","gram","\u30b0\u30e9\u30e0");
mDbHelper.createCrv("mijikai","short","\u307f\u3058\u304b\u3044");
mDbHelper.createCrv("minami","south","\u307f\u306a\u307f");
mDbHelper.createCrv("miru","watch","\u307f\u308b");

查询:

 String query = "SELECT docid as _id," + 
    KEY_ENGLISH + "," +
    KEY_JAPANESEALPHA + "," +
    KEY_JAPANESECHAR+ 
    " from " + FTS_VIRTUAL_TABLE +
    " where " +  KEY_JAPANESEALPHA + " = '" + inputText + "';";

我也有Cursor:

 private void showResults(String query) {

        Cursor cursor = mDbHelper.searchCrvJapanesechar((query != null ? query.toString() : "@@@@"));
        if (cursor == null) {
            Toast.makeText(getApplicationContext(), 
                    "No Search Found!", Toast.LENGTH_LONG).show();

        } else {

            // Specify the columns we want to display in the result 
            String[] from = new String[] {
                    DBAdapter.KEY_JAPANESECHAR,
                   DBAdapter.KEY_JAPANESEALPHA,
                   DBAdapter.KEY_ENGLISH
                   };
                    //DBAdapter.KEY_TAGALOG};


            // Specify the Corresponding layout elements where we want the columns to go
            int[] to = new int[] {     R.id.sjapanesechar,
                   R.id.sjapanesealpha,
                    R.id.senglish};
                   // R.id.stagalog};

对于复合词,我需要最小化我的数据库,以便在

Input: kiroguramu

我可以连接kiru的英语术语和guramu的英语术语。这将导致

Result: kilogram

抱歉,我无法粘贴我的样本图片,因为我是新手。 我在http://www.mysamplecode.com/2011/11/android-searchview-using-sqlite-fts3.html获得了检索数据。这是一个很好的帮助。 三江源。

1 个答案:

答案 0 :(得分:1)

您好我认为您应该尝试在此处阅读一些基本的JSON解析 http://www.androidhive.info/2012/01/android-json-parsing-tutorial/