Frank
Frank

Reputation: 579

Remove data in a large txt file of all the occurrence in a database table

I have a DB table A which contains approx 4,000,000 records. I also have a file containing 2,500,000 records.What I want to do is to remove all the occurrence in table A in the txt file.

eg:
data.txt:

1234
5678
9012
3456

Table A:

1234
abcd
efgh
3456

What I want to get is a file with below data, which removed all the occurrence in Table A:

5678
9012 

I have tried to do this by reading the txt file line by line and query DB each time, which will take years to complete the task. I want to know the best way to do this using Java, considering the performance, speed and loading.

Upvotes: 1

Views: 38

Answers (1)

Hang
Hang

Reputation: 395

Create a temporary table B to load the txt file in, then do a join query to get the result, then drop table B. You probably need index to speed things up.

Upvotes: 1

Related Questions