0

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

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

尝试

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

从 SQL Server Management Studio 中正确获取行上的锁。我能够在其他行上执行SELECTUPDATE指示。

如果我尝试相同但使用 JDBC 整个表被锁定。

任何帮助表示赞赏

4

1 回答 1

1

Look at the isolation level of your session.

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

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.

Best Regards.

于 2013-02-27T13:55:56.227 回答