java - Bad SQLITE update Performance -


i new in sql(now working on sqlite application) , section in app when try piece of code:

public void addsong(librarysong song){      for(int i=0; i<intopanel.getcomponentcount(); i++)  //check if doublicates exist         if(song.getname().equals(intopanel.getcomponent(i).getname()))             return;       intopanel.add(song);          //add song database table     try{         container.database.connection.preparestatement("insert '"                 + container.libwindow.libinfowindow.currentlib.getname()+ "'"   //table name                 + " (path,stars,date,hour) values ('"                 + song.getname() + "'," + song.stars + ",'"                 + song.datecreated + "','" + song.hourcreated + "')").executeupdate();     }catch(sqlexception sql){ sql.printstacktrace(); }; } 

the problem: above method add song jtable , database table.the problem performance bad database.why might happen? use statement somewhere wrong or have to update different way?thanks reply.

the expensive part of accessing database not execution of statement itself, synchronizations done transactions.

by default, each sql command put automatic transaction, overhead of them.

if have multiple updates, should group them single transaction:

container.database.connection.setautocommit(false); ... (...)     addsong(...); container.database.connection.commit(); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -