How to disable the field cache in ServerPreparedStatement
Posted by: f worm
Date: April 18, 2018 03:55AM

Use 6.0.6 version, enable useServerPrepStmts.
The statement is cached by connection, the statement will remain until the connection is really closed.

Suppose a statement query "select * from xxx",
then "alter table xxx add column fx...",
query "select * from xxx" again,
throw an exception:

Exception in thread "main" java.sql.SQLException: java.lang.ArrayIndexOutOfBoundsException: 5
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:545)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:505)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:479)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:489)
at com.mysql.cj.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:724)
at com.mysql.cj.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1923)
at org.apache.commons.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)

I have to enable useServerPrepStmts to improve performance and save cost.
My application need "select *", alter table column, then "select *" in the same statement.

So I modify the MergingColumnDefinitionFactory's createFromFields, refresh columnDefinitionFromCache:

public ColumnDefinition createFromFields(Field[] fields) {
return this.columnDefinitionFromCache = new MysqlaColumnDefinition(fields);
}

Does't merge the flags, may be have some unknow issue.
Is there an elegant way to meet the needs?

Options: ReplyQuote


Subject
Written By
Posted
How to disable the field cache in ServerPreparedStatement
April 18, 2018 03:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.