Remove All Ads from XDA

adding an image column to an existing tabe in sqlite database

7 posts
Thanks Meter: 0
By SufiyanSadiq, Junior Member on 13th March 2014, 03:29 PM
Post Reply Email Thread
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...
6th April 2014, 02:00 AM |#2  
MattMatt0240's Avatar
Senior Member
Thanks Meter: 197
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
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes