extracted a method in database connection