java database relates query handing on order management