所以我有一个 SQLite 数据库,其中包含 stop_number、stop_lat 和 stop_lon 列。我找不到关于如何搜索停止编号并返回相应的 stop_lat 和 stop_lon 的连贯答案?我已经尝试了几种查询命令的变体,但我似乎无法做到恰到好处。对数据基础的新手有什么帮助吗?
问问题
131 次
2 回答
1
尝试类似的东西
Cursor cursor = mDatabase.query( TABLE_STOP,
new String[] { KEY_STOP_LAT, KEY_STOP_LONG },
KEY_STOP_NUMBER + "=?",
new String[] { <your stop number as string> },
null,
null,
null);
if(cursor.getCount()>0){
cursor.moveToFirst();
float stop_lat = cursor.getFloat(0); // first column requested in the second query argument
float stop_long = cursor.getFloat(1); // second column requested in the second query argument
}
cursor.close();
文档在这里。
于 2013-07-31T02:43:53.767 回答
0
尝试运行此查询。我在我的情况下工作。
DataBaseHelper databaseManager = new DataBaseHelper(this);
databaseManager.openDataBase();
SQLiteDatabase db = databaseManager.getWritableDatabase();
uCursor = db.rawQuery("select distinct stop_number from tablename", null);
if(uCursor != null && uCursor.getCount() > 0) {
while (uCursor.moveToNext()) {
String stop_number = uCursor.getString(uCursor.getColumnIndex("stop_number"));
Cursor cursor = db.rawQuery("select distinct stop_lang, stop_lat from table where stop_number = "+stop_number, null);
if(cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String stop_lang = cursor.getString(cursor.getColumnIndex("stop_lang"));
String stop_lat = cursor.getString(cursor.getColumnIndex("stop_lat"));
}
}
}
}
于 2013-07-31T05:53:47.073 回答