added try catch blocks to database work

added try catch blocks to all database work