Hi all,
That's what I need:
Select an unique register and lock it, both read and write.
On demand, unlock register and update its value.
Thats' what I did:
I use Spring's JdbcTemplate to access data. To lock this register I use 'for update' statement. In other words:
However this seems to lock only write not read. Is it possible to lock read, too? That is, throw an exception (or sqlcode or whatever which I can realize whether is locked) if I try to read a register, which is locked.Code:private final String query = "select TIPO_CONTADOR, ID_CONTADOR, VALOR_CONTADOR, FECHA " + "from T_CONTADORES where TIPO_CONTADOR = ? AND ID_CONTADOR = ? for update"; private final String update = "update T_CONTADORES set VALOR_CONTADOR = ? " + "where TIPO_CONTADOR = ? AND ID_CONTADOR = ?"; [...] ContadorData cd = (ContadorData) this.jdbc.queryForObject(query, new Object[]{tipoCont, idCont}, new RowMapper(){ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { [...]} });
Sorry if this question is already asked and answered. I didn't find it.
Thanks a lot.
Regards.



Reply With Quote

