Preventing queries caching in MySQL

后端 未结 3 779
一个人的身影
一个人的身影 2021-01-19 15:42

I\'m using the tomcat connection pool via JNDI resources.

In the context.xml:



        
3条回答
  •  走了就别回头了
    2021-01-19 16:01

    As documented under Consistent Nonlocking Reads:

    If the transaction isolation level is REPEATABLE READ (the default level), all consistent reads within the same transaction read the snapshot established by the first such read in that transaction. You can get a fresher snapshot for your queries by committing the current transaction and after that issuing new queries.

    [ deletia ]

    If you want to see the “freshest” state of the database, use either the READ COMMITTED isolation level or a locking read:

    SELECT * FROM t LOCK IN SHARE MODE;
    

    You can set the default transaction isolation level in Tomcat via its Resource@defaultTransactionIsolation attribute.

提交回复
热议问题