I defined a method to add an entry in my database helper class and insert data into database using it, but it is not working. This is my method defined in databasehelper class:
public void createchannelEntry(ChannelPoster channel) {
openDB();
ByteArrayOutputStream out = new ByteArrayOutputStream();
channel.getPoster().compress(Bitmap.CompressFormat.PNG, 100, out);
ContentValues cv = new ContentValues();
cv.put(KEY_POSTER, out.toByteArray());
cv.put(KEY_CHANNEL, channel.getChannel());
cv.put(KEY_PATH, channel.getPath());
cv.put(KEY_DBLINK, channel.getDBlink());
mDb.insert(channelS_TABLE, null, cv);
closeDB();
}
this is how I insert data
Bitmap sherlock = BitmapFactory.decodeResource(getResources(), R.drawable.sherlock);
mDB.createchannelEntry(new ChannelPoster(sherlock, "aa" ,"ll" ,"ha" ));
and I have a JavaBean for holding an entry
public class ChannelPoster {
private Bitmap poster;
private String channel;
private String path;
private String dblink;
public ChannelPoster(Bitmap pi, String c, String p, String d) {
poster = pi;
channel = c;
path = p;
dblink = d;
}
public Bitmap getPoster() { return poster; }
public String getChannel() { return channel; }
public String getPath() { return path; }
public String getDBlink() { return dblink; }
}
And because I am adding entries one by one, the program runs very slow, so it’s there a faster way to insert many entries? like get all of them in one event?
I suggest not saving the images in the database, but rather saving them as files, and saving a path to them in the database (using a normal
TEXTfield).If you don’t want to do that, there are two things that will still greatly improve the speed of your processing:
Something like that:
(the
finallyis there to make sure you close the transaction and the connection even if it somehow fails during the inserts: in this case ALL your inserts will be cancelled)