DERBY-4653, the same issue is happening for Connection.rollback().
The methods Connection.rollback() in the client driver cause a round-trip to the server even if the rollback is unnecessary (i.e. there is nothing to roll back).
Comments suggest (see below) that this can be optimized, such that the commands are flowed to the server only when required. It can be seen that this optimization has been used other places in the client driver. Never the less, it must be checked that this optimization doesn't have side-effects and does not create regression.
// Even if we're not in a transaction, all open result sets will be closed.
// So we could probably just return if we're not in a transaction
// using the following code:
// if (!this.inUnitOfWork)
The protocol tests should be added too.