-1

我有一个存储在字符串中的图像路径:

if(uri != null) {
              Cursor cursor = getContentResolver().query(uri, new String[] {   
                                       android.provider.MediaStore.Images.ImageColumns.DATA}, 
                                       null, null, null);
                    cursor.moveToFirst();
                    String image = cursor.getString(0);             
                    cursor.close();

如何将此字符串插入/检索到该数据库中/从该数据库中检索?

private static final String DATABASE_CREATE =
    "create table " + DATABASE_TABLE + " ("
            + KEY_ROWID + " integer primary key autoincrement, "
            + KEY_IMAGE + " text not null)"; 
4

1 回答 1

1

你应该使用ContentValues实例和insert()方法SQLiteDatabase

ContentValues cv = new ContentValues();
cv.put(<column>, <data>);   
cv.put(<column>, <data>);
cv.put(<column>, <data>);       
db.insert(<tableName>, <columnHackNull>, cv);

这种方式一般推荐且干净。

编辑:

对于从数据库中检索数据,基本示例:

String SELECT_QUERY = "SELECT * FROM Table";
Cursor c = db.rawQuery(SELECT_QUERY , null);

或使用 whereArgs

String SELECT_QUERY = "SELECT * FROM Table WHERE id = ?";
String[] whereArgs = {"<data>","<data>"};
Cursor c = db.rawQuery(SELECT_QUERY , whereArgs );
于 2012-05-31T11:13:33.400 回答