Dean Chen
Dean Chen

Reputation: 3890

Can't see inserted data from MySQL immediately

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.

Upvotes: 1

Views: 2037

Answers (1)

user330315
user330315

Reputation:

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.

So you have two options

  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

Upvotes: 4

Related Questions