I actually faced an issue for a Sybase ASE database using DatabasePopulator.execute() and ScriptUtils.executeSqlScript().

I run a small script which looks similar to this example:

declare @id int

select @id = id from test where value = '123'

delete from other_one where test_id = @id
delete from other_two where test_id = @id
go

The reading of the script and splitting it into statements work absolutely fine when setting "go\n" as separator.

But when it comes to execution, the script will just be executed every third time which is very weird.

My expectation would be that the the select and delete statements are executed every time.

So when debugging and adjusting the executeSqlScript() method I found that there are multiple result sets and updateCounts which are delivered by the statement and Sybase needs explicitly all to be called here.

This problem seems already to be known for SQL server as well, as I found on Stackoverflow.

So my adjustment would be to add explicit handling for more results at this spot here:

https://github.com/spring-projects/spring-framework/blob/321a804449e78451f8ed22703ae93accb3a5139f/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java#L261-L262

This could look like this for example:

try {
    boolean results = stmt.execute(statement);
    int rowsAffected = stmt.getUpdateCount();
    while (results || rowsAffected != -1) {
        rowsAffected = stmt.getUpdateCount();
        // debug logging
        results = stmt.getMoreResults(Statement.CLOSE_CURRENT_RESULT);
    }
}