MySQL updates are updated forever

Hey, I'm trying to use about 600,000 tokens in my MySQL database. The engine I use is InnoDB. The update process lasts forever :( So I’m best guessing that I missed something in my code and that what I’m doing is just plain stupid.

Maybe someone has a spontaneous idea of ​​what seems to eat up my work:

Here is my code:

public void writeTokens(Collection<Token> tokens){

    try{
        PreparedStatement updateToken = dbConnection.prepareStatement("UPDATE tokens SET `idTag`=?, `Value`=?, `Count`=?, `Frequency`=? WHERE `idToken`=?;");

        for (Token token : tokens) {

            updateToken.setInt(1, 0);
            updateToken.setString(2, token.getWord());
            updateToken.setInt(3, token.getCount());
            updateToken.setInt(4, token.getFrequency());
            updateToken.setInt(5, token.getNounID());

            updateToken.executeUpdate();
        }
    }catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Thank you so much!

+5
source share
3 answers

I don't have a Java-specific answer for you, but wrap the entire shebang in a transaction. If you do not, then MySQL (when writing to InnoDB) will start working and make a new transaction for the update statement.

START TRANSACTION COMMIT /. , MySQL , , .

+5

, , , .

PreparedStatement addBatch() - , , , . 600 000 1 - :)

+4

. .

, :

. , .

+3

All Articles