Quote
What I am confused about is that setString handles it this deviating encoding correctly, while setCharacterStream does not. How can that be?
That's just how MySQL Server handles big-size data.
By submitting data through `setString()` you are telling the driver to send it attached to the MySQL protocol command
COM_STMT_EXECUTE which is encoded using the session character set; while `setCharacterStream()` sends the data isolated via
COM_STMT_SEND_LONG_DATA, which is binary encoded, and then followed by the corresponding `COM_STMT_EXECUTE` that actually runs the query. This difference makes the server handle character sets differently and, hence, two distinct connection properties for encoding configurations.
In theory, the connector could encode the character stream data using the target encoding as returned from the server in the query preparation phase, however, like I explained before, this only works with server-side prepared statements and if we used this information, then client-side and server-side prepared statements would behave differently (see
useServerPrepStmts for more details) and we can't allow that.