没有找到值时,Android Sqlite什么都不返回

Abh*_*ngh -2 database sqlite android

我正在使用此方法来调用将从sqlite数据库中搜索videoname的查询.作为回报,当视频名称存在时,我会获得Row_id_2的值,但是当没有找到任何视频名称时,我什么也得不到.请让我知道我该怎么办?我想要一些事件,如果没有找到..没有错误没有警告.

public String seeVideoEntry(String VideoName) {


Cursor cursor = ourDatabase.query(Table_Name_2, new String[] {
Row_Id_2, Row_VideoName, Row_VideoCapturedTime, Row_VideoUrl,
Row_VideoDate, Row_VideoUri }, Row_VideoName + "=?",
new String[] { VideoName }, null, null, null, null);

try {
if (cursor != null) {
cursor.moveToFirst();
Log.e("Test1", VideoName);

}

} catch (Exception e) {
e.printStackTrace();
}return cursor.getString(cursor.getColumnIndex(Row_Id_2));

}
Run Code Online (Sandbox Code Playgroud)

CL.*_*CL. 5

阅读moveToFirst文档:

如果光标为空,则此方法将返回false.

您必须检查以下内容的返回值moveToFirst():

public String seeVideoEntry(String videoName) {
    Cursor cursor = ourDatabase.query(Table_Name_2,
                                      new String[] { Row_Id_2 },
                                      Row_VideoName + "=?",
                                      new String[] { videoName },
                                      null, null, null, null);
    if (cursor.moveToFirst()) {
        return cursor.getString(0);
    } else {
        return "not found";
    }
}
Run Code Online (Sandbox Code Playgroud)