Added DB lookup function.
I must close() the writer to make sure all things are printed before the program terminates.