-1

我有一个两列数据的 sqlite3 数据库。我在数据库上执行了以下查询。它适用于字符串单词。我如何将单词数组(单词 [i])传递给 gettestdata 以在数据库上执行查询

 public Cursor getTestData(word) 
 { 
     try 
     { 


         String sql ="SELECT suggest_text_2 FROm FTSdictionary WHERE suggest_text_1='"+word+"'"; 

         Log.v("Query",sql );

         Cursor mCur = mDb.rawQuery(sql, null); 
         if (mCur!=null) 
         { 
            mCur.moveToNext(); 
         } 
         return mCur; 
     } 
     catch (SQLException mSQLException)  
     { 
         Log.e(TAG, "getTestData >>"+ mSQLException.toString()); 
         throw mSQLException; 
     } 
 }
4

1 回答 1

1

您可以使用类似这样的 sql 查询:

String mQuery = "";
for (int i = 0; i < words.length; i++) {
    mQuery.length() < 1 ? mQuery += "'" + words[i] + "'" : mQuery += ", '"+ words[i] + "'";
}
String sql ="SELECT suggest_text_2 FROm FTSdictionary WHERE suggest_text_1 in ('"+ mQuery +"')"; 

我没有测试过它,但它应该可以工作。

于 2013-04-29T13:41:26.770 回答