Better database insert and handing of Resourse excepetion in main