[英]how to access other columns of an android sqlite database when i have info from one column's record
I have an activity where it shows an image from the phone`s sd card, and I have the path of the image that was passed from another activity to the current activity as an intent extra, example: //mnt/sdcard/DCIM/pic05.png 我有一个活动,其中显示了手机sd卡中的图像,并且我有从另一个活动传递到当前活动的图像的路径,以作为额外的意图,例如:// mnt / sdcard / DCIM / pic05.png
the path is stored in the database under the column named _data and there are other columns for each record that are there, like description and _display_name, how do I access these? 路径存储在数据库中名为_data的列下,并且每个记录还有其他列,例如description和_display_name,我该如何访问它们?
for example I have the path like the one shown above, pic05.png and I want to show the _display_name in a textview for that pic, that is what I am trying to find out how to do. 例如,我具有上面显示的路径pic05.png,并且我想在该图片的文本视图中显示_display_name,这就是我试图找到的方法。
Simple SQL would do, based on a table: 简单SQL将基于表执行以下操作:
CREATE TABLE pictures
( fileName TEXT NOT NULL,
displayName TEXT,
PRIMARY KEY pictures_pk( fileName ) );
You could simply: 您可以简单地:
SELECT displayName
FROM pictures
WHERE fileName = ?
Or in Java: 或在Java中:
SQLiteDatabase db...
String displayName;
Cursor c = db.query( "pictures", null, "fileName=pic01.png", null, null, null, null );
c.moveToFirst();
if( !c.isAfterLast() )
displayName = c.getString(1);
This is very simplified. 这是非常简化的。 You'll need to pass the columns you want and use proper column-index when you access the cursor. 访问游标时,您需要传递所需的列并使用适当的column-index。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.