Could we use a framework, or otherwise reorganize the code interacting with the database?
Activity