Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Contributor
Posts: 35
Registered: ‎02-02-2012
My Device: 9300
My Carrier: Vodafone

Re: App runs slowly with JSON

Thanks maadani for your help!
I've tryed what you said me, and now my code looks like this:

int l=json.getLenght();
JSONObject jObj=new JSONObject();
       
st = db.createStatement("INSERT INTO Dendak(ID,Izena,Helbidea,Telefonoa,Emaila,Mota,Produktuak,Ordutegia,Horario,Latitud,Longitud,Argazkia,Web,Txartela,Berezitasunak,Especialidades) VALUES (?,?, ?, ?,?,?,?,?,?,?,?,?,?,?,?,?)");
       st.prepare();
       
       for (int i=0; i<l;i++)
       { 
        jObj=json.getJSONObject(i);
        st.bind(1, jObj.getInt("id"));
        st.bind(2, jObj.getString("izena"));
        st.bind(3, jObj.getString("helbidea"));
        st.bind(4,jObj.getString("telefonoa"));
        st.bind(5,jObj.getString("emaila"));        
        st.bind(6, jObj.getInt("mota"));
        st.bind(7, jObj.getString("produktuak"));
        st.bind(8,jObj.getString("ordutegia"));
        st.bind(9, jObj.getString("horario"));
        st.bind(10,jObj.getInt("latitud"));
        st.bind(11, jObj.getInt("longitud"));
        st.bind(12, jObj.getString("argazkia"));
        st.bind(13, jObj.getString("web"));
        st.bind(14, jObj.getInt("txartela"));
        st.bind(15, jObj.getString("berezitasuna"));
        st.bind(16, jObj.getString("especialidad"));
        
        st.execute();
        st.reset();        
        
       }
       
       st.close();

 

Json is an JsonArray that I get from my web service, and has more or less 200 objects.

I run this code, and I need more or less 3 minutes for entering all to my database.

 

Any idea of how to do it faster?

I've done something nearly same for Android and runs much faster....

Developer
Posts: 228
Registered: ‎10-01-2011
My Device: Passport

Re: App runs slowly with JSON

I think like any database, you can gain performance by optimising your commits. Have you tried wrapping in a transaction then experimenting with the optimum batch size for commits.

 

I not also you are writing to an SD card, is there an issue with the card?

Chris

Contributor
Posts: 35
Registered: ‎02-02-2012
My Device: 9300
My Carrier: Vodafone

SQLite slow insert

[ Edited ]

Thank yor Chris for your answer.
I have not tryied wrappung in a transaction, because I don't find how to do that... Any documentation?
I'm writing to an SD card and I don't have any issues with the card!

Highlighted
Developer
Posts: 228
Registered: ‎10-01-2011
My Device: Passport

Re: SQLite slow insert

Like this:

 

int count = 0;

final int batchSize = 20; // number records to process before commiting the transaction

boolean dirty = false;

 

while (have more record) {

   db.beginTransaction();

 

    // execute your insert statement 

  st.prepare...

  st.execute ...

    

    // see if we have processed the same number of records in our batch size  

    if (count % batchSize ==0){    

         db.commitTransaction();

         dirty = false;

    } else

        dirty = true;

}

 

if (dirty)  // commit any records that are in the final incomplete batch

       db.commitTransaction();

 

 

I would also suggest you compare how it performs if you write to anywhere other then the SD card, just to take that factor our of the equation.

 

Chris