我正在玩我的SQL Server 2012试图抓住锁.根据我看到的教程,我尝试测试获取表上的独占锁,以便其他任何查询都无法从中读取信息,直到事务未结束,但它只是不起作用.即使它在视频中工作,这是我在第一个窗口中的查询:
use TSQL2012
BEGIN transaction
update tele with (TABLOCKX, holdlock)
set cor = '12'
waitfor delay '00:05'
go
Run Code Online (Sandbox Code Playgroud)
然后在第二个查询窗口中我尝试了:
select * from tele
Run Code Online (Sandbox Code Playgroud)
它工作得很好,虽然理论上应该有"排他性"锁定防止这种情况.为什么会这样?我也尝试过
set transaction isolation level serializable on
Run Code Online (Sandbox Code Playgroud)
并且没有延迟但选择总是成功的.有任何想法吗?
我试图编写一个简单的程序,它将生成随机的3个整数,然后将它们放在数组中,然后将它们连接成一个整数序列,但它会抛出一个错误
这是代码:
int [] kol=new int[3];
for(int j=0;j<3;j++) {
kol[j]=(int)Math.round(Math.random() * 89999) + 10000;
System.out.print(kol[j] +"\n" );
}
String ma=kol[0]+","+kol[1]+","+kol[2]+";";
System.out.println(ma);
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
int b = Integer.parseInt(Integer.toString(kol[0]) + Integer.toString(kol[1]) +
Integer.toString(kol[2]));
System.out.println(b);
Run Code Online (Sandbox Code Playgroud)
但同样的错误:
Exception in thread "main" java.lang.NumberFormatException: For input
at java.lang.NumberFormatException.forInputString(Unknown Source)
string: "715534907077099"
Run Code Online (Sandbox Code Playgroud)