javadocumentumdocumentum6.5dfc

How do you access the value of a DQL count() query in Java Program


I want to get to the value I am finding using the COUNT command of DQL.Normally I enter the column name I want to access into the getInt() getString() method. What I'm supposed to do when there is no specific colomn name.

{
    String query = "select count(*) as count from dm_user;";
    return query;           
}

Code to fetch the result

{
    IDfCollection total = dql.execute(session, IDfQuery.DF_READ_QUERY);

    while (total.next()){
        cint = total.getInt("count");
}

Tomcat Result

DfException:: THREAD: http-8080-2; MSG: [DM_QUERY_E_SYNTAX]error: "A Parser Error (syntax error) has occurred in the vicinity of: select count(*) as count"; ERRORCODE: 100; NEXT: null


Solution

  • You are using count which is a keyword for your column custom name, the error you posted clearly says it: A Parser Error (syntax error)

    This will do

    select count(*) as quantity from dm_user;
    

    and fetching result like

    IDfCollection total = dql.execute(session, IDfQuery.DF_READ_QUERY);
    
        while (total.next()){
            cint = total.getInt("quantity");
    

    will work