且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java MYSQL / JDBC查询从缓存的Connection返回过时数据

更新时间:2023-02-16 21:14:32

原来这是一个未经审查的问题。感谢Brent Worden关于交易的问题让我环顾四周,注意到我已经禁用了自动提交,并且在查询后没有提交。

Turns out it was a matter of uncommited queries. Thanks to Brent Worden for the question about transactions which led me to look around and notice that I had disabled auto commit and was not committing after queries.

所以解决方案有效对我来说:

So the solutions that worked for me:

conn.setAutoCommit(true);

statement.executeQuery(query);
conn.commit();

这样可以刷新查询并防止过时数据。

This allows the queries to be flushed out and stale data is prevented.