2013-07-31 6 views
-1

열을 반환하므로 열이 stop_number, stop_lat 및 stop_lon 인 SQLite 데이터베이스가 있습니다. 정지 번호를 검색하고 해당 stop_lat 및 stop_lon을 반환하는 방법에 대한 일관된 답을 찾을 수 없습니까? 여러 가지 유사 검색어 명령을 시도했지만 올바르게 이해할 수없는 것 같습니다. 데이터 기반을 처음 접하는 누군가를위한 도움?안드로이드 SQLite 데이터베이스 및

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 같은

+3

귀하가 시도한 것을 게시하십시오. – Azad

+0

테이블 이름이 어디입니까? – Peshal

+0

database.rawquery ("STOP", "stop_number", "status =?", null, null, null, null); 나는 데이터베이스 쿼리를 배우는 좋은 refrence조차도 정말 우둔한 것이다. 차가운 물에서 너를 점프하는 모든 것을 발견한다. –

답변

1

보십시오 뭔가.

+0

이것이 작동합니다. –

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")); 

        } 
       } 

      } 
     } 
관련 문제