2011-10-10 42 views
0

我有一些示例代碼,我一直在玩。基本上我只是從csv文件讀取並寫入表格。可以在下面加以改進,以使其更快似乎很慢我可以改進此代碼以更快地讀取和寫入數據嗎?

public void impcusdata() throws SQLException, IOException { 
    try { 

     String UnitID = getUnitID(); 
     FileReader fr = new FileReader("/mnt/sdcard/CRM.CSV"); 

     // Put the file into the buffer 
     BufferedReader in = new BufferedReader(fr); 
     db.execSQL("DELETE FROM " + CUSTOMER_TABLE); 
     // Create a new string to hold the data 
     String data = ""; 

     // Create the strings executing SQL commands for the data to be 
     // inserted 
     String InsertCustString = "INSERT INTO " + CUSTOMER_TABLE 
       + " VALUES("; 
     String InsertEndString = ");"; 

     // If there is any data in the .CSV file then read it. 
     while ((data = in.readLine()) != null) { 
      // String the results to the SQL database 
      db.execSQL(InsertCustString + data + InsertEndString); 
     } 
    } catch (SQLiteException ex) { 
     String Shaw = ex.getMessage(); 

    } 
    // log entry to the LogCat file 
    Log.v(TAG, "Customer Table has been updated"); 
} 
+0

它可能是可以改進的。但有時猜測瓶頸是不可能的。嘗試[測量](http://android-developers.blogspot.com/2010/10/traceview-war-story.html),看看有什麼確切的問題。 – 2011-10-10 22:11:36

回答

相關問題