22,209
社区成员
发帖
与我相关
我的任务
分享
String sql ="insert into tb(f)values('v') select SCOPE_IDENTITY()";
ResultSet rs = stmt.executeQuery(sql);
int keyValue = -1;
if (rs.next()) {
keyValue = rs.getInt(1);
}
create table tb(id int identity(1,1),ar varchar(10))
insert into tb
select 'a' union all
select 'b'
go
insert into tb select 'c'
select SCOPE_IDENTITY()
insert into tb select 'd'
insert into tb select 'e'
select SCOPE_IDENTITY()
drop table tb
/*
(1 行受影响)
---------------------------------------
3
(1 行受影响)
(1 行受影响)
---------------------------------------
5
(1 行受影响)