所以我有一个SQLite数据库,其列有stop_number,stop_lat和stop_lon。我找不到关于如何搜索停止号并返回相应的stop_lat和stop_lon的连贯答案?我已经尝试了几种查询命令,但我似乎无法正确使用它。对数据基础新手的任何帮助?
答案 0 :(得分: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();
文档here。
答案 1 :(得分: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"));
}
}
}
}