4

From java using MySql database, how can check whether a row or range of rows is locked in a table ?

Muhammad Ali Qasmi
  • 121
  • 1
  • 1
  • 6

2 Answers2

2

If you want to check if a table is locked then you can try like this:

SHOW OPEN TABLES

but you cannot check if a range of rows is locked.

You can also make it specific for a particular table like this:

SHOW OPEN TABLES WHERE `Table` LIKE '[YOURTABLENAME]' 
AND `Database` LIKE '[YOURDATABASENAME]' AND In_use > 0;

As per my opinion when a table is locked then the rows are locked automatically.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
-1

MySQL uses only table-level locking. If you want row level locking capabilities, switch to InnoDB(A suggestion not a must).

diyoda_
  • 5,274
  • 8
  • 57
  • 89
  • 1
    `InnoDB` is a database engine used by `MySQL`, so your answer isn't exactly correct. – Kayaman Sep 11 '15 at 07:35
  • @Kayaman You are correct, I should add somewhere to the answer about the MyISAM Storage Engine. But obviously the user seems to be using InnoDB engine. – diyoda_ Sep 11 '15 at 07:39