简体   繁体   English

当我有一个列的记录中的信息时,如何访问android sqlite数据库的其他列

[英]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.

相关问题 如何使用其他列的值从数据库获取PRIMARY KEY? (Android,SQLite) - How do I get PRIMARY KEY from database using another column's value? (Android, SQLite) 收到此异常:“android.database.sqlite.SQLiteException: no such column: _id: , while compile”当我有一个 _id 列 - Getting this exception: “android.database.sqlite.SQLiteException: no such column: _id: , while compiling” when I have an _id column SQLite数据库从其他数据库的列复制数据 - Sqlite database copies data from other database's column 在Android SQLite数据库中,如何匹配数据库的多个表中具有相同ID的特定列值? - In Android SQLite db how to match particular columns values which have same id's in multiple tables of a database? 如何使用Android应用程序从sqlite中的assest文件夹将表从一个数据库复制到另一个数据库 - How to copy table from one database to other database from assest folder in sqlite with an Android application 如何将所有记录从一个表复制到Android Sqlite中同一数据库中的另一个表 - How to copy all the record from one table to the another table in the same database in android Sqlite 在Android中是否可以从另一个应用程序访问sqlite3 db? - Is it Possible to access the sqlite3 db of one application from other in Android? 如何使用Android sqlite数据库更新一行中的多列? - How to update multiple columns in one row using android sqlite database? 如何从Android中的数据库(SQLite)中选择特定记录? - How to select a particular record from database(SQLite) in android? 如何使用Sqlite访问一个应用程序的数据库到另一个应用程序? - How to access one App's Database to another Application using Sqlite?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM