At this time, I have some case in developing android application, right now I have some class called DBHelper, this class is use to execute operation like create table and operation like create trigerrs and so on.. In this case I tried to execute sql statement for inserting data in my table, but the sql operation is not working, can anybody help me? I really need help here.
Here's my class..
public class DBHelper extends SQLiteOpenHelper
{
private Context mContext;
private static final String db_name ="schoolmap.db";
private static final int db_version=1;
//Constructor
public DBHelper(Context context) {
super(context, db_name, null, db_version);
this.mContext = context;
}
private static final String db_TABLE_foto = "create table "
+ "foto" + "("
+ id + " integer primary key autoincrement, "
+ caption_foto + " varchar(20), "
+ image + " BLOB);";
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(db_TABLE_foto);
//in this line i tried to add picture from the drawable folder
Bitmap b = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.a1);
int bytes = b.getByteCount();
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
b.copyPixelsToBuffer(buffer);
byte[] array = buffer.array();
//the question is right here, when I try this code, it's not working, means: the record is not
//inserted
ContentValues values = new ContentValues();
values.put(caption_foto, "Test");
values.put(image, array);
// Inserting Row
database.insert(foto, null, values);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DBHelper.class.getName(),"Upgrading database from version " + oldVersion + "to"
+ newVersion + ",which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + db_TABLE_foto);
onCreate(db);
}
so I mean, when I running this apps first time, I tried to add picture in my application, but the sql operation is not working, can somebody help about this issue? Any Help is Needed