1

I am working inserting multiple records in databse at same time

here is the code :-

public synchronized boolean execute_Batch_Query(final JSONArray accObj) 
{
    boolean value = false;

    UiApplication.getUiApplication().invokeLater(new Runnable() 
    {
        public void run() 
        {
            String sqlStatement = "INSERT INTO Records_Table(id ,name ,description) " +"VALUES (?,?,?)";

            try 
            {
                JSONArray jsonArray = accObj;
                int size = jsonArray.length();
                Statement st = db.createStatement(sqlStatement);
                st.prepare();

                for(int i =0 ; i<size ; i++)
                {
                    JSONObject jsonObj = (JSONObject)jsonArray.getJSONObject(i);
                    String id = Global.EMPTY;
                    String name = Global.EMPTY;
                    String description = Global.EMPTY;
                    id      = jsonObj.getString("id");
                    name    = jsonObj.getString("name");
                    description = jsonObj.getString("description");
                    st.bind(1,id);
                    st.bind(2,name);
                    st.bind(3,description);

                    st.execute();
                    st.reset();


                }
                st.close();
                Log.d("SQL", sqlStatement);
            } 
            catch ( Exception e ) 
            {
                Log.e(e.getMessage());
            } finally {
                // close();
            }
        }
    });
    return value;
}

This code inserts 10-15 records at a time but after that I am getting Disk I/O error. Please let me know why I am getting I/O error.

AK Joshi
  • 877
  • 6
  • 20

1 Answers1

1

This is actually not an answer, but just some considerations.

  1. You code looks OK (meaning it should work under normal conditions).

  2. You get net.rim.device.api.database.DatabaseException: disk I/O error. This does not tell the exact reason. DatabaseException has 3 sub-classes with defined reasons:

    • DatabaseBindingException - indicates a failure to bind the parameter to a SQL statement.
    • DatabaseIOException - indicates that database file failed to be opened, created, opened or created, or deleted.
    • DatabasePathException - indicates that the path to a database file is malformed.

Since you don't get any of the stated above exceptions, it is impossible to define the actual reason.

Ideas:

  • try another SD Card
  • do a reset (pull out the battery)
  • try another device with the same BB OS version
  • try a device running another BB OS version
Vit Khudenko
  • 27,639
  • 10
  • 56
  • 86
  • @Mario: No, I just thoroughly reviewed your code and the API docs. – Vit Khudenko May 31 '13 at 08:56
  • hmm..k , can you please let me know any alternate way for doing batch insertion in BB , because I am stack at a point ...there around 2500 + records . For batch insertion in Android -Iphone it will take around 5 sec but in Blackberry it will take around 6-7 mins , I am inserting oneByone records, every time for a single insertion databse open/close operation fire. – AK Joshi May 31 '13 at 09:56
  • Try checking the http://stackoverflow.com/questions/1609637/is-it-possible-to-insert-multiple-rows-at-a-time-in-an-sqlite-database. They propose an alternative sql for batch insertion, however i don't know if BB supports it. Also be aware there is a limit on slq request length which depends on BB OS version, so don't try to use the only request for the entire data set. – Vit Khudenko Jun 02 '13 at 11:09
  • Also this is worth checking: http://docs.blackberry.com/en/developers/deliverables/8682/BP_Optimizing_SQLite_database_performance_767361_11.jsp. Specifically check the 'Use explicit transactions' point. – Vit Khudenko Jun 02 '13 at 11:19
  • Please just let men know what actually helped you with this issue. – Vit Khudenko Jun 04 '13 at 15:54