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

试试这个

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 回答
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 回答