SQL Server-使用JDBC的行锁 [英] SQL Server - Row Lock with JDBC

查看:138
本文介绍了SQL Server-使用JDBC的行锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JDBC锁定SQL Server表上的一行?

Is it possible to lock a single row on a SQL Server table using JDBC?

我正在使用jTDS驱动程序v1.2.7和SQL Server 2005.

I'm using jTDS driver v1.2.7 and SQL Server 2005.

尝试

UPDATE myTable SET timestamp=GETDATE() WHERE id='myid'

从SQL Server Management Studio

可以在行上正确获取锁.我可以在其他行上执行SELECTUPDATE指令.

from SQL Server Management Studio the lock is acquired correctly on the row. I'm able to perform SELECT and UPDATE instructions on other rows.

如果我尝试相同的操作,但使用JDBC,则整个表都被锁定.

If I try the same but using JDBC the entire table is locked.

感谢您的帮助

推荐答案

查看会话的隔离级别.

select session_id,login_name,program_name,
date_format,quoted_identifier,arithabort,
ansi_null_dflt_on,ansi_defaults,ansi_warnings,
ansi_padding,ansi_nulls,concat_null_yields_null,
case transaction_isolation_level  
when 0 then 'Unspecified'
when 1 then 'ReadUncomitted'
when 2 then 'ReadCommitted'
when 3 then 'Repeatable'
when 4 then 'Serializable'
when 5 then 'Snapshot'
end as transaction_isolation_level,
deadlock_priority
from sys.dm_exec_sessions

也许您的选择由于使用READ COMMITTED而被阻止.当您离开时,UPDATE将仅阻止该单行打开事务.

Maybe your SELECT becomes blocked because you are using READ COMMITTED. The UPDATE will block only that single row as you leave opened the transaction.

最好的问候.

这篇关于SQL Server-使用JDBC的行锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆