0

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

techraf
  • 64,883
  • 27
  • 193
  • 198
Zeus07
  • 168
  • 1
  • 5
  • 17

2 Answers2

4

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

Miki
  • 2,493
  • 2
  • 27
  • 39
  • you can mark answer as accepted (it seems that you don't do it on your other questions as well) – Miki Oct 03 '16 at 20:22
2

While @Miki answered it already but I like to add one small thing here that below code should work too if you haven't specified any alias.

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

  while (total.next()){
    cint = total.getInt("count(*)");
  }
}
Sanjeev Dhiman
  • 1,169
  • 1
  • 11
  • 20