Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,805,161 Members 52,855 Now Online
XDA Developers Android and Mobile Development Forum

adding an image column to an existing tabe in sqlite database

Tip us?
(Last edited by SufiyanSadiq; 13th March 2014 at 02:34 PM.) Reason: forgot to add something
Junior Member - OP
Thanks Meter 0
Posts: 7
Join Date: Jan 2014
Location: Hyderabad
Default adding an image column to an existing tabe in sqlite database

I wanted to add a column which will be able to store images, to an existing sqlite table which has two columns, What datatype column do i create so that i can be able to store images in my database?
My code looks like this

public class Sqlite extends SQLiteOpenHelper {

public static final String DB_NAME = "vault";
public static final int DB_VERSION = 1;
public static final String DB_CREATE = "CREATE TABLE data(key VARCHAR(32) PRIMARY KEY NOT NULL, value VARCHAR(100) NOT NULL)";

public SQLiteDatabase db;
public Context context;

public Sqlite(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.context = context;

public void onCreate(SQLiteDatabase db) {
this.db = db;

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

public synchronized void close() {
if(this.db != null) {

public List<VaultItem> getAll() throws Exception {
// load items
List<VaultItem> items = new ArrayList<VaultItem>();

// query db
Cursor c = db.query("data", new String[]{"key", "value"}, null, null, null, null, null);
while(!c.isAfterLast()) {
items.add(new VaultItem(c.getString(0), SimpleCrypto.decrypt(c.getString(1))));
return items;

public VaultItem getOne(String key) throws Exception {
Cursor c = db.query("data", new String[]{"key", "value"}, "key = '"+key+"'", null, null, null, null);
VaultItem item=null;
while(!c.isAfterLast()) {
item = new VaultItem(c.getString(0), SimpleCrypto.decrypt(c.getString(1)));
return item;

This table only stores, .txt documents, with their name and content. I want it to to be able to store .doc documents and .jpg files. Please help me...
MattMatt0240's Avatar
Senior Member
Thanks Meter 98
Posts: 225
Join Date: Sep 2011
A Blob data type is what you would want to store in a database for images. has good info on it.

Basically take your image (bitmap) and convert to byte[] to store in db. Retrieve it by converting byte array to bitmap.

Do not forget to update your DB version to update db with new fields.

Noted to self thrice via tapatalk
Root it and boot it!

Samsung Galaxy Note 3 | PAC-ROM

Retired phones: Epic Touch 4G| Evo shift 4g | Evo 4g
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes