find data in sql and write info to file