I've two posts during my table "res_allocation", one "ResName" along with other "PID", "ResName" may have multiple values for any single "PID".

It is possible to single query for upgrading values of "ResName" in multiple rows according to PID?

The brand new values for "ResName" comes dynamically i.e., its a person input. I personally use SQL database.

It has been modified from code I curently have... there might be a mistake or two, however the crux works (it really works during my code). Ideally such things as do this by having an ORM tool like Hiberante.

Essentially you place in the batch update after which run statement.executeBatch() to complete the particular update. You're came back by having an int[] array using the results. You check these against a listing of predefined constants to determine what's going on. This really is Considerably faster than performing each update individually. In addition, you are able to mix all of the updates in a single transaction, making rollbacks simpler.

public void updateResNames(List<ResAllocationDTO> list) {
    String sql = "UPDATE res_allocation SET ResName = ? WHERE PID = ?";
    PreparedStatement statement = null;
    try {
        statement = connection.prepareStatement(sql);
        for (ResAllocationDTO dto : list) {
            statement.setString(1, dto.getResName());
            statement.setString(2, dto.getPID());
            statement.addBatch();
        }
        int[] result = statement.executeBatch();
        for (int i = 0; i < result.length; i++) {
            if (result[i] == PreparedStatement.EXECUTE_FAILED) {
                throw new SQLException(String.format("Entry %d failed to execute in the batch insert with a return code of %d.", i, result[i]));
            }
        }
        commit();
    } catch (SQLException e) {
        logger.error(LoggerCodes.DATABASE_ERROR, e);
        rollback();
        throw new RuntimeException(e);
    } finally {
        close(statement);
    }
}

commit(), close() and rollback() appears like this:

public void close(PreparedStatement statement) {
    try {
        if (statement != null && !statement.isClosed())
            statement.close();
    } catch (SQLException e) {
        logger.debug(LoggerCodes.TRACE, "Warning! PreparedStatement could not be closed.");
    }
}

protected void commit() {
    try {
        if ((connection != null) && !connection.getAutoCommit()) {
            connection.commit();
        }
    } catch (SQLException e) {
        logger.debug(LoggerCodes.TRACE, "Warning! ResultSet could not be closed after commit.");
    }
}

protected void rollback() {
    try {
        if ((connection != null) && !connection.getAutoCommit()) {
            connection.rollback();
        }
    } catch (SQLException e) {
        logger.debug(LoggerCodes.TRACE, "Warning! ResultSet could not be closed after rollback.");
    }
}

I really hope this can help you! Best of luck and happy coding!