I wouldn't classify "it crashes" as a performance problem. What is the error message you get? I believe you need to start from there.
Without much more details of the processing, the best you can get is some very vague general advice. I'm not sure this would be true specifically in DB2, but generally I'd say you'll get the best performance by using SQL statements to manipulate the data in bulk. Does DB2 have some documentation regarding performance?