I need to dump all the contents from a table into a csv file. I googled a bit and scoured SO to find an answer but I can't seem to find what I'm looking for exactly, here's what I found : Android - Generate CSV file from table values and http://howtodoinjava.com/2014/08/12/parse-read-write-csv-files-opencsv-tutorial/. Here's my DB :
public class DBhelper extends SQLiteOpenHelper {
//TABLE COLUMNS
private static final String[] COLUMNS = {DBhelper.ID, DBhelper.GIFTCARDS_NUMBER, DBhelper.GIFTCARDS_CREATED,
DBhelper.GIFTCARDS_CREATOR, DBhelper.GIFTCARDS_BALANCE};
private static final String ID = "_id";
private static final String GIFTCARDS_NUMBER = "number";
private static final String GIFTCARDS_CREATED = "created";
private static final String GIFTCARDS_CREATOR = "creator";
private static final String GIFTCARDS_BALANCE = "balance";
//DATABASE INFORMATION
static final String DB_NAME = "GiftcardsDB";
//DATABSE VERSION
static final int DB_VERSION = 1;
// TABLE QUERY
private static final String CREATE_TABLE = "CREATE TABLE giftcards ( " + ID +
" INTEGER PRIMARY KEY AUTOINCREMENT, " + GIFTCARDS_NUMBER + " TEXT NOT NULL, " + GIFTCARDS_CREATED +
" TEXT NOT NULL, " + GIFTCARDS_CREATOR + " INTEGER NOT NULL, " + GIFTCARDS_BALANCE + " REAL);";
public DBhelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS Giftcards");
onCreate(db);
}
I'd like some explanation on how does CSVWriter and/or ResultSet works. Thanks in advance !