I'm using ArcObjects/Java for ArcGIS 10.2.2 and I'm trying to get unique values of a field for a feature class.

Here's my current code:

List<String> values = new ArrayList<String>();

int fieldId = featureClass.findField(fieldName);

IQueryFilter queryFilter = new QueryFilter();

((IQueryFilterDefinition2)queryFilter).setPrefixClause("DISTINCT " + fieldName);

IFeatureCursor cursor = featureClass.search(queryFilter, false);
IFeature feature = null;

while((feature = cursor.nextFeature()) != null) {

return values;

In theory, by using the 'prefix clause', the SQL statement should be SELECT DISTINCT field FROM ... WHERE ... but when I execute this code, I'm getting an:

AutomationException : An invalid SQL statement was used. [SELECT DISTINCT CLASS_ADM * FROM TRONCON_ROUTE]


The problem is this * after the DISTINCT clause that shouldn't be here.

I tried to set subFields to nothing like:




but this doesn't solve the problem.

I also tried to use IDataStatistics.getUniqueValues but it returns a deprecated type IEnumVARIANT that I don't know how to use..

Any idea to get that working?

1 Answer 1


I just found the solution (several minutes after..).

Subfields have to be set to the fieldName:


and it works very fast!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.