java如何在spring中将表锁定为独占模式
Noob-spring问题。如何在spring中运行下面的sql语句。到目前为止,我只使用了使用到postgresql数据库的JDBC连接的“NamedParameterJdbcTemplate”类
begin;
lock table tx_test_queue in exclusive mode;
update tx_test_queue
set status='running'
where
job_id in (
select job_id
from tx_test_queue
where status='queued'
order by job_id asc
limit 1 )
returning job_id;
commit;
这是我正在使用的Java代码,它不起作用
private static final Logger logger = LoggerFactory.getLogger( BatchQueueDAO.class );
@Autowired
private NamedParameterJdbcTemplate template;
public BatchQueueBean getNextBatchJob() {
MapSqlParameterSource params = new MapSqlParameterSource();
StringBuilder sql = new StringBuilder();
sql.append( "begin;" );
sql.append( "lock table batch_queue in exclusive mode;" );
sql.append( "update batch_queue set status_cd=2 where id in ( select id from batch_queue where status_cd=1 order by id asc limit 1) returning id;" );
sql.append( "commit;" );
SQLBuilderUtil.printMap( params, logger );
List<BatchQueueBean> r = template.query( sql.toString(), new BeanPropertyRowMapper<>( BatchQueueBean.class ) );
if( r.isEmpty() )
return null;
else
return r.get( 0 );
}
它正在返回一个由:org引起的。postgresql。util。PSQLException:查询“错误”未返回任何结果
共 (0) 个答案