Hi,
I am trying to update approx. 3800 rows in a table in two steps:
1. set all values to 0
2. set some of them in a loop to a calculated value
The first step is fast (< 1 s). However the second step takes around 3 s. Maybe there is some problem in the code, because if I run the code without the first step or run the first query on another table, the second step is very fast, too (< 0.1 s). It is slow only when executed after the first step on the same table.
Here is some code:
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");conn=DriverManager.getConnection("jdbc:ucanaccess://"+path+";singleconnection=true","","");//Firstupdate(resetallvalues)longstart=System.currentTimeMillis();PreparedStatementps2=conn.prepareStatement("UPDATE mytab SET val = 0.0;");ps2.executeUpdate();ps2.close();System.out.println("Update 1: "+(System.currentTimeMillis()-start)/1000.0+" s");//Secondupdatestart=System.currentTimeMillis();conn.setAutoCommit(false);intcount=0;PreparedStatementps=conn.prepareStatement("UPDATE mytab SET val = ? WHERE id = ?;");for(intj=1;j<=3600;j++){doublevalue;//calculatesomevalue....value=1.3;//updatetableundercertainconditionsif(true){ps.setDouble(1,value);ps.setInt(2,j);ps.addBatch();count++;}if(count>200){ps.executeBatch();count=0;}}ps.executeBatch();conn.commit();System.out.println("Update 2: "+(System.currentTimeMillis()-start)/1000.0+" s");
How to avoid this? Maybe some mistake?
Thank you for any advice!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to update approx. 3800 rows in a table in two steps:
1. set all values to 0
2. set some of them in a loop to a calculated value
The first step is fast (< 1 s). However the second step takes around 3 s. Maybe there is some problem in the code, because if I run the code without the first step or run the first query on another table, the second step is very fast, too (< 0.1 s). It is slow only when executed after the first step on the same table.
Here is some code:
How to avoid this? Maybe some mistake?
Thank you for any advice!
This issue is being addressed on Stack Overflow.