Re: How to disable the field cache in ServerPreparedStatement
Posted by:
f worm
Date: April 18, 2018 09:39PM
Thinks.
Maybe I didn't explain it correctly. Yes, I use connection pool, but not for this reason.
The url is: jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useCursorFetch=true&useServerPrepStmts=true&cachePrepStmts=true
When connection prepareStatement(sql), it create ServerPreparedStatement, and read out the column information to ServerPreparedStatement.resultFields.
Then executeQuery, read out fields from fieldPacket, and merge with the resultFields.
The problem will be here -- merge.
Finally close the ServerPreparedStatement, it's not really closed, just cached by connection.
The next query for the same sql will reuse this cached statement.
If the sql is like this "select *...", and table's column has been changed(add or remove), the statement resultFields will not match the fields read from fieldPacket, merge(@MergingColumnDefinitionFactory) will throw ArrayIndexOutOfBoundsException.
This scene is not common, and it can't be solve at present when set useServerPrepStmts as true.
Could consider adding a parameter to solve this requirement, or this is a conflict usage and not support?