I am not sure what is your use case and why do you want to EXPLICITLY lock a row programmatically. Generally this happens under the hood when you use JDBC/Transaction APIs.
Quoting @Keith Randall from the link shared above by @ Mithun Sasidharan,
"If you have an index on tblAreas.AreaID, then any transaction that
includes WHERE tblAreas.AreaID in (...) will lock the index for those
entries"
This will generally use and Optimistic Locking. What you are interested seems is Pessimistic locking.
In MySQL, one way to do is to use SELECT FOR UPDATE
statement which will lock the selected rows for you. Please refer to the respective documentation for the usage.