0

I have an image save as blob in SQLite database,Now i want that image blob data to be saved on a file and i also need to insert the blob data from the file back into the database.I actually want this to be done pragmatically done using android.Any ideas how to do it?Don't tell me to show some research i have done.I'm new to android programming and trying to learn.So please help me.

Omg its not a duplicate question.The question is how to fetch blob data from a database and save it in a seperate file(May b csv file) and insert bytes data from file into sqlite db.

try {
        c = db.rawQuery("SELECT * FROM " + TABLE_NAME_USER_PROFILE, null);
        int rowcount = 0;
        int colcount = 0;
        File sdCardDir = Environment.getExternalStorageDirectory();
        String filename = "userProfile.csv";

        // the name of the file to export with
        File saveFile = new File(sdCardDir, filename);
        FileWriter fw = new FileWriter(saveFile);

        BufferedWriter bw = new BufferedWriter(fw);
        rowcount = c.getCount();
        colcount = c.getColumnCount();
        if (rowcount > 0) {
            c.moveToFirst();

            for (int i = 0; i < colcount; i++) {
                if (i != colcount - 1) {

                    bw.write(c.getColumnName(i) + ",");

                } else {

                    bw.write(c.getColumnName(i));

                }
            }
            bw.newLine();

            for (int i = 0; i < rowcount; i++) {
                c.moveToPosition(i);

                for (int j = 0; j < colcount; j++) {
                    if (j != 7) {
                        if (j != colcount - 1)
                            bw.write(c.getString(j) + ",");
                        else
                            bw.write(c.getString(j));
                    } else
                        bw.write((c.getBlob(7)) + ",");
                }
                bw.newLine();
            }
            bw.flush();
            Log.e("tag", "Exported Successfully.");
            Log.e("tag", "Exported Successfully to" + sdCardDir);
        }
        c.close();


    } catch (Exception ex) {
        Log.e("catch", ex.getMessage().toString());
    }

0 Answers0