我在两列中有一个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;
}
}
答案 0 :(得分: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 +"')";
我没有测试过,但它应该有用。