Skip to content Skip to sidebar Skip to footer

Dynamic Database Backup For Certain Tables

I need to backup just some of the tables in my main database. The other tables are reference and are static so do not need to be backed up. I have created a new blank DB that is on

Solution 1:

I wrote a class to handle this. Yes my DB is at least 95% reference...

Here is the guts of the code:

Cursorc= DbBak.rawQuery(Sql, null);
            String Cn[] = c.getColumnNames();

            if (c != null ) {
                if  (c.moveToFirst()) {
                    do {
                        for ( x=0; x< c.getColumnCount(); x++)
                        {
                            newRow.put(Cn[x].toString(), c.getString(x));
                        }

                        Db.insert(TableName,  null, newRow);

                    }while (c.moveToNext());

Solution 2:

Unless your reference tables make up 95% of your database size, I'd just copy the database file using standard Java file I/O, while the database is closed. That will be substantially faster than trying to schlep the data over cell-at-a-time.

Post a Comment for "Dynamic Database Backup For Certain Tables"