Helper类不返回存储在SQLite数据库中的图像名称

时间:2013-09-14 05:57:15

标签: android database image sqlite android-sqlite

我正在尝试从SQLite数据库中检索图像路径并在ImageView上显示相应的图像。问题是,helper类没有返回图像名称,因此,我无法在ImageView中显示图像。请参阅以下helper.class代码

public static final String GETSD = "select DISTINCT FileName from Photos where 
 last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from Photos where 
 DisplayCount in (select MIN(DisplayCount) from Photos));";

public static final String UPDATE_DISP = "update Photos set DisplayCount = 
 Displaycount+1 where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) 
 from Photos where DisplayCount in (select MIN(DisplayCount) from Photos));";

public static final String UPDATE_TIMESTAMP = "update Photos set 
 last_disp_TimeStamp = CURRENT_TIMESTAMP where FileName in (select FileName from
 Photos where last_disp_TimeStamp in (select MIN(last_disp_TimeStamp) from Photos 
 where DisplayCount in (select MIN(DisplayCount) from Photos)));";

    public String getSDPath() {
        // TODO Auto-generated method stub
        Cursor c;
        SQLiteDatabase myDB ;
        String commonpath = "/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/";

        String result="";
        String h = "";
         try {

              myDB=this.openDataBase();                   

                  c=myDB.rawQuery(GETSD,null);
                  myDB.execSQL(UPDATE_DISP);

                  myDB.execSQL(UPDATE_TIMESTAMP);


                 if (c != null ) {
                     if  (c.moveToFirst()) {
                     do {

                         // put your code to get data from cursor                      
                         int img = c.getColumnIndex("FileName");
                         result = c.getString(img);
                         h=commonpath+result;
                             final String imageFilePath = c.getString(img);
                         Log.v("IMAGE PATH====>>>> ", imageFilePath);


                  }while (c.moveToNext());
                     }

                  }



                  if(c != null)
                 {
                     myDB.close();
                     c.close();
                  }                    
                  }catch(SQLException sqle){

                  throw sqle;

                  }

        return h;
    }

查询工作正常,当我在SQLite浏览器上测试它时,查询没有任何问题。我检查了/data/data/com.example.myappname/databases/文件夹中的数据库文件。我在/storage/sdcard/DCIM/Camera/SAMPLE IMAGES/中有所需的照片。

此函数返回的路径是/ storage / sdcard / DCIM / Camera / SAMPLE IMAGES /。但是这个函数的预期字符串是/ storage / sdcard / DCIM / Camera / SAMPLE IMAGES / xxx.png

字符串“xxx.png”存储在数据库中,使用查询GET_SD,我正在检索图像的名称。

0 个答案:

没有答案