Final Database access code

when implemented, remove the main function. It is just for testing.