0

I am updating status value of a table in db(mysql), i.e -2 to 0 through jdbc connection in java, now i need to fetch all those rows having 0 as status, in other method. Now when i am trying to fetch all those values having status 0, the recent updated rows are not included. I think there might be some buffer issues but not sure about it, can somebody help me out about the solution regarding the above issue.

Edit:- Currently I am using something like this.

connection.setAutoCommit(false);
String taskUpdateString = "update query"
taskStatement = connection.prepareStatement(taskUpdateString);
taskStatement.execute();
connection.commit();
Atiq
  • 490
  • 11
  • 28

2 Answers2

0

updates in mysql happen as immediate after commit. but for the update mysql has to aquire a lock on the table or row, (for details: http://dev.mysql.com/doc/refman/5.7/en/internal-locking.html). so it might be cause mysql is waiting for locks, or the buffering is on the query side

0

Are you sure you are closing all the java connections properly?

When you are done with using your Connection, you need to explicitly close it by calling its close() method in order to release any other database resources (cursors, handles, etc) the connection may be holding on to.

The safe pattern in Java is to close your ResultSet, Statement, and Connection (in that order) in a finally block when you are done with them, something like" ... See answer with 55 ticks on Stack overflow here: Closing Database Connections in Java

Hope that helps.

Community
  • 1
  • 1