Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If every row should get a different value that cannot be derived from the existing data in the database, there is not much you can do to optimize the overall complexity. So do not expect too much wonders.</p> <p>That said, you should start using prepared statements and batching:</p> <pre><code>public void updateRank(Map&lt;Integer,Double&gt; map){ Iterator&lt;Entry&lt;Integer, Double&gt;&gt; it = map.entrySet().iterator(); String query = ""; int i = 0; Connection connection = getConnection(); // get the DB connection from somewhere PreparedStatement stmt = connection.prepareStatement("update profile set rank = ? where profileId = ?"); while (it.hasNext()) { Map.Entry&lt;Integer,Double&gt; pairs = (Map.Entry&lt;Integer,Double&gt;)it.next(); stmt.setInt(1, pairs.getValue()); stmt.setDouble(2, pairs.getKey()); stmt.addBatch(); // this will just collect the data values it.remove(); } stmt.executeBatch(); // this will actually execute the updates all in one } </code></pre> <p>What this does:</p> <ol> <li>the prepared statement causes the SQL parser to only parse the SQL once</li> <li>the batching minimizes the client-server-roundtrips so that not one for every update</li> <li>the communication between client and server is minimized because the SQL is only transmitted once and the data is collected and sent as a packet (or at least fewer packets)</li> </ol> <p>In addition:</p> <ul> <li>Please check if the database column <code>profileId</code> is using an index so that looking up the respective row is fast enough</li> <li>You could check if your connection is set to auto-commit. If so try to disable auto-commit and explicitly commit the transaction after all rows are updated. This way the single update operations could be faster as well.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload