query and store balance in database