现在做一个从excel导数据到数据库中,用java实现的,现在的问题是excel中的几列中的数据填写的是名称,导入时要校验名称在数据库中是否存在,如果存在则保存其id到数据库中,如果数据少的话没有什么问题,如果现在数据多的话怎么办?
比如说现在excel中有n万行数据,其中一列是姓名、一列是学历,......,而存放姓名那张表有几十万条数据,学历那个有几十万条数据,怎么验证和得到其id比较好呢。总不能每次从数据库中查,也不能一次都加载到内存,急啊!!!!
比如说现在excel中有n万行数据,其中一列是姓名、一列是学历,......,而存放姓名那张表有几十万条数据,学历那个有几十万条数据,怎么验证和得到其id比较好呢。总不能每次从数据库中查,也不能一次都加载到内存,急啊!!!!
e.gcreate table a
(id int,
name varchar(20)
);
insert into a values(1,'aaa');
insert into a values(2,'bbb');
insert into a values(3,'ccc');
insert into a values(4,'ddd');
insert into a values(5,'eee');
insert into a values(6,'fff');
create table b
(id int,
name varchar(20)
);
insert into b(name) values('aaa');
insert into b(name) values('bbb');
insert into b(name) values('ccc');
insert into b(name) values('ggg');
insert into b(name) values('hhh');
insert into b(name) values('iii');
--关联更新B中的数据
update b set b.id=(select a.id from a where a.name=b.name);
--将B中id不为空的数据保存到需要的C表中
insert into C(clom1,colm2...) select c1,c2... from B where b.id is not null