Database comparator in java (Simple)