Java code for Database interaction and layout changes