无法立即查看来自MySQL的插入数据 [英] Can't see inserted data from MySQL immediately

查看:70
本文介绍了无法立即查看来自MySQL的插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JDBC.我的测试应用程序将一些数据插入MySQL,然后通过相同的连接进行查询.我有四台计算机,一台是MySQL服务器,三台是UBuntu Desktops.在一台UBuntu Desktop中,我的测试应用程序运行到这个问题,但是我在其他UBuntu桌面上找不到这个问题. 另外,如果在插入后创建新连接以查询数据,则可以找到该数据. mysql-connector-java库为5.1.17.我尝试了5.1.18,但问题仍然存在.

I am using JDBC.My test application inserts some data into MySQL,then query it via the same connection.I have four computers,one is MySQL server,three are UBuntu Desktops.In one UBuntu Desktop,my test application run into this problem,but I don't find this problem in other UBuntu Desktops. Also,If I create a new connection to query data after inserting,I can find the data.The version of mysql-connector-java library is 5.1.17.I tried 5.1.18,but the problem still exists.

推荐答案

MySQL的默认隔离级别为"REAPEATABLE READ",这意味着如果您在查询工具中未使用自动提交,则不会看到其他提交的数据.交易,除非您通过发出COMMIT或ROLLBACK结束自己的交易.

The default isolation level for MySQL is "REAPEATABLE READ", that means if you are not using autocommit in your query tool, you will not see committed data from other transactions unlesse you end your own transaction by issuing a COMMIT or ROLLBACK.

创建新连接后可以看到数据的事实也指向该方向.

The fact that you can see the data after creating a new connection also points into that direction.

所以您有两个选择

  1. 将查询"连接的隔离级别更改为读取已提交"
  2. 在运行SELECT之前,在查询工具中
  3. 发出COMMIT(或ROLLBACK)
  1. change the isolation level for your "query" connections to "READ COMMITTED"
  2. issue a COMMIT (or ROLLBACK) in your query tool before running the SELECT

这篇关于无法立即查看来自MySQL的插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆