Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void exportTables (View view) {
- File dbFile = getDatabasePath("database.db");
- Banco dbhelper = new Banco(getApplicationContext());
- File exportDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
- if (!exportDir.exists()) {
- exportDir.mkdirs();
- }
- File file = new File(exportDir, tableName +".csv");
- try {
- file.createNewFile();
- CSVWriter csvWriter = new CSVWriter(new FileWriter(file));
- SQLiteDatabase db = dbhelper.getReadableDatabase();
- Cursor curCSV = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table' AND name NOT LIKE 'android_metadata' AND name NOT LIKE 'sqlite_sequence'", null);
- csvWriter.writeNext(curCSV.getColumnNames());
- while(curCSV.moveToNext()) {
- //Table Collumms
- String arrStr[] ={curCSV.getString(0),curCSV.getString(1)};
- csvWriter.writeNext(arrStr);
- }
- csvWriter.close();
- curCSV.close();
- }
- catch(Exception sqlEx) {
- Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
- }
- Toast.makeText(this, "FILE EXPORTED WITH SUCCESS!", Toast.LENGTH_SHORT).show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement