2017-04-23 19 views
0

私は自分のアプリケーションでSQLiteテーブルを実装しましたが、今はそれをデバイス自体にエクスポートします。 Where exported CSV file is saved?デバイス上のCSVでエクスポートされたSQLite DBが見つかりません

と、この:私はこれに非常に似たコードに続く

http://paragchauhan2010.blogspot.co.uk/2012/08/database-table-export-to-csv-in-android.html

それでいてを、関係なく、私はいじくり回すか、CSVファイルには、私のデバイス上に表示されません。私はsdカードがマウントされていませんが、外部記憶装置が今シミュレートされているので、それは問題ではありませんか?

エクスポート方法:

private void exportDB() { 

    File dbFile = getDatabasePath("emotionSQLTable.db"); 
    EmotionListDbHelper dbhelper = new EmotionListDbHelper(getApplicationContext()); 
    //switching out to internal directory here, for debu purposes and because we dont have sd card 
    final String appPath = String.format 
      (
        "%s/Aletheia", Environment.getExternalStorageDirectory() 
      ); 

    File exportDir = new File(appPath); 
    if (!exportDir.exists()) { 
     exportDir.mkdirs(); 
    } 

    String fileName = new SimpleDateFormat("yyyyMMddHHmm").format(new Date()); 
    //TODO for debugging purposes 
    File file = new File(exportDir, "emotionSQLTable.csv"); 
     try { 
     file.createNewFile(); 
     CSVWriter csvWrite = new CSVWriter(new FileWriter(file)); 
     SQLiteDatabase db = dbhelper.getReadableDatabase(); 
      //Here we select from the TABLE NAME, which is emotionlist 
     Cursor curCSV = db.rawQuery("SELECT * FROM emotionlist", null); 
     csvWrite.writeNext(curCSV.getColumnNames()); 
     while (curCSV.moveToNext()) { 
      //Which column you want to exprort 
      String arrStr[] = {curCSV.getString(0), curCSV.getString(1), curCSV.getString(2)}; 
      csvWrite.writeNext(arrStr); 
     } 
     csvWrite.close(); 
     curCSV.close(); 
    } catch (Exception sqlEx) { 
     Log.e("MainActivity", sqlEx.getMessage(), sqlEx); 
    } 


} 

DBHelperクラス

public class EmotionListDbHelper extends SQLiteOpenHelper { 
private static final String DATABASE_NAME = "emotionSQLTable.db"; 

private static final int DATABASE_VERSION = 1; 

public EmotionListDbHelper(Context context) { 
    super(context, DATABASE_NAME, null, DATABASE_VERSION); 
} 

public void onCreate(SQLiteDatabase sqLiteDatabase) { 
    String SQL_CREATE_WAITLIST_TABLE = "CREATE TABLE emotionlist(_id INTEGER PRIMARY KEY AUTOINCREMENT, anger DOUBLE NOT NULL, contempt DOUBLE NOT NULL, disgust DOUBLE NOT NULL, fear DOUBLE NOT NULL, happiness DOUBLE NOT NULL, neutral DOUBLE NOT NULL, sadness DOUBLE NOT NULL, surprise DOUBLE NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"; 
    sqLiteDatabase.execSQL("CREATE TABLE emotionlist(_id INTEGER PRIMARY KEY AUTOINCREMENT, anger DOUBLE NOT NULL, contempt DOUBLE NOT NULL, disgust DOUBLE NOT NULL, fear DOUBLE NOT NULL, happiness DOUBLE NOT NULL, neutral DOUBLE NOT NULL, sadness DOUBLE NOT NULL, surprise DOUBLE NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP);"); 
} 

public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 
    sqLiteDatabase.execSQL("DROP TABLE IF EXISTS emotionlist"); 
    onCreate(sqLiteDatabase); 
} 

はこれまでのところ、私は無駄に、内部メモリに格納、AsyncTaskにコードを移動しようとしました。任意のアドバイスをいただければ幸いです。

答えて

0

解決済みの問題はSQLiteコードではありません。ボタンonClickListener自体のバグでした。ボタンはメソッドをまったく呼び出さなかった。

関連する問題