Select to view content in your preferred language

How create a IQueryDef2 java?

467
1
03-02-2012 11:04 AM
BetyMartinez
New Contributor
Hi, everybody.

I want to make a query for find duplicates in a geodatabase using Java and arcobjects (Argis v10). I have the next code in Java:

public void getDuplicate(IFeatureClass fClass, Workspace wS) throws IOException{
        String field = "DLLAVE, COUNT(*) AS C";               
        String postfix = "GROUP BY DLLAVE HAVING C > 1";                
        String where = fClass.getOIDFieldName()+" IS NOT NULL";
        IFeatureWorkspace fw = wS;
       
        IQueryDef2 query = (IQueryDef2) fw.createQueryDef();              
        query.setPostfixClause(postfix);
        query.setSubFields(field);
        query.setWhereClause(where);
        query.setTables(fClass.getAliasName());

        ICursor search = query.evaluate2(true);
        IRow row = search.nextRow();
        while(row != null){
            String id = (String) row.getValue(search.findField("DLLAVE"));
            String cont = (String) row.getValue(search.findField("C"));
            System.out.println("IDLLAVE: "+id);
            System.out.println("COUNT: "+cont);
            row = search.nextRow();
        }      
}

But.... throw the next exception:

IQueryDefProxy cannot be cast to com.esri.arcgis.geodatabase.IQueryDef2Proxy

Help me =(

Does anyone know how to get a IQueryDef2?

Note: Sorry for my english.
0 Kudos
1 Reply
LeoDonahue
Deactivated User
The createQueryDef() method in Workspace returns an IQueryDef, of which IQueryDef2 is a subinterface.  What you want is an actual QueryDef.

"IQueryDef2 query = (IQueryDef2) fw.createQueryDef();               "

What you are doing here is trying to assign a cast of IQueryDef as IQueryDef2 to an IQueryDef2 type.  fw.createQueryDef() already returns an IQueryDef type and you're trying to cast that as an IQueryDef2.

http://help.arcgis.com/en/sdk/10.0/java_ao_adf/api/arcobjects/com/esri/arcgis/geodatabase/IQueryDef....

What class implements both of those interfaces? ... QueryDef.
0 Kudos