Handling DB exception and creating URL dynamically based on date