Android sqlite select语句不能正常工作
我有三个表,我想用E sql语句进行查询,但它不能很好地工作,因为它不能提供所有可能的结果 守则:Android sqlite select语句不能正常工作,android,sql,sqlite,Android,Sql,Sqlite,我有三个表,我想用E sql语句进行查询,但它不能很好地工作,因为它不能提供所有可能的结果 守则: public void setsuchresultat(String pSearchword) { String[] table = new String[]{"tbl_A", "tbl_B", "tbl_C"}; String[] column = new String[]{"columnA", "columnB" }; // Type varchar(50) not null
public void setsuchresultat(String pSearchword)
{
String[] table = new String[]{"tbl_A", "tbl_B", "tbl_C"};
String[] column = new String[]{"columnA", "columnB" }; // Type varchar(50) not null
String[] search = new String[]{"%" + pSearchword+ "%", pSearchword+ "%", "%" + pSearchword, pSearchword};
getdata(table,column,search);
}
public void getdata(String[] pTable, String[] pColumn, String[] pSearch)
{
for(String t:pTable)
{
for(String s : pColumn)
{
for(String k : pSearch)
{
Cursor c = this.db.rawQuery("SELECT * FROM " + t + " WHERE " + s + " LIKE '"+ k + "'", null);
if ((c.moveToFirst()) || c.getCount() > 0)
{
while(c.moveToNext())// Suchresultat abspeichern
{
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
}
}
}
}
}
}
我认为问题在你们的循环中,若你们检查 改变
if ((c.moveToFirst()) || c.getCount() > 0)
{
while(c.moveToNext())// Suchresultat abspeichern
{
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
}
}
到
是的,先生。非常感谢你!
if (c.moveToFirst() || c.getCount() > 0) /* OR if (c != null && c.moveToFirst())*/ {
do {
String col1 = c.getString(c.getColumnIndex("columnA"));
String col2 = c.getString(c.getColumnIndex("columnB"));
} while(c.moveToNext());
}