2
int getIdForSong(Song song){

    String selectQuery = "SELECT id FROM " + TABLE_SONG + " WHERE " + SONG_TITLE + "=" + song.getSongTitle() + " AND " + ARTIST_NAME + "=" + song.getArtistName();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    int id = Integer.parseInt(cursor.getString(0));
    return id;
}

「=」の近くで例外が発生しています。誰?

4

3 に答える 3

1

selectQuery の値を次のように変更します。

"SELECT id FROM " + TABLE_SONG + " WHERE " + SONG_TITLE + " = '" + song.getSongTitle() + "' AND  '" + ARTIST_NAME + "' = '" + song.getArtistName() + "'";
于 2012-10-27T10:21:52.273 に答える
0

CursorOutOfBoundExceptionの場合、

カーソル後cursor=db.rawQuery(selectQuery、null); 、

if(null!= cursor && cursor.moveToFirst()){

  int id = Integer.parseInt(cursor.getString(0));
  return id;

}

于 2012-10-27T11:06:26.607 に答える
0

これを試して

int getIdForSong(Song song){

String selectQuery = "SELECT id FROM " + TABLE_SONG + " WHERE " + SONG_TITLE + "= ' " + song.getSongTitle() + "' AND " + ARTIST_NAME + "= ' " + song.getArtistName()+" ' ";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
int id = Integer.parseInt(cursor.getString(0));
return id;
}
于 2012-10-27T10:21:42.923 に答える