RE: How to get result from SELECT count(*) FROM ...

From: noban (noba..andex.ru)
Date: Wed Nov 30 2005 - 04:54:47 EST

  • Next message: noban: "Connections & Pooling"

    Thank`s!

    >Oh yeah, for to mention ...
    >
    >The value you'll get back is most likely String and you'll need to get the intValue() of it.
    >
    >/dev/mrg
    >
    >
    >-----Original Message-----
    >From: Gentry, Michael (Contractor) [mailto:michael_gentr..anniemae.com]
    >Sent: Monday, November 28, 2005 9:39 AM
    >To: cayenne-use..bjectstyle.org
    >Subject: RE: How to get result from SELECT count(*) FROM ...
    >
    >
    >I do something like this:
    >
    >
    >final String queryString = "select count(*) 'rowCount' from Foo";
    >final SQLTemplate queryTemplate = new SQLTemplate(Foo.class, queryString, true);
    >queryTemplate.setFetchingDataRows(true);
    >List results = dataContext.performQuery(queryTemplate);
    >if (results.size() == 1)
    > System.out.println("Count = " + ((DataRow) results.get(0)).get("rowCount"));
    >else
    > System.out.println("Count = 0");
    >
    >
    >Of course, I haven't tried to compile that ... :-)
    >
    >Also, your select statement might need to be written as: select count(*) as 'rowCount' ... Depends on your SQL Server. Try in an SQL window first for correct syntax. The above syntax should work for Sybase and probably SQL Server.
    >
    >/dev/mrg
    >
    >PS. I thought we had a wiki page for this ... I might add it.
    >
    >
    >-----Original Message-----
    >From: noba..andex.ru [mailto:noban@yandex.ru]
    >Sent: Monday, November 28, 2005 3:25 AM
    >To: cayenne-use..bjectstyle.org
    >Subject: How to get result from SELECT count(*) FROM ...
    >
    >
    >Hi!
    >
    >One more question:
    >
    >How to get result from "SELECT count(*) FROM ... "?

    -- 
    Сегодня удачный день, чтобы завести почту на Яндексе http://mail.yandex.ru
    



    This archive was generated by hypermail 2.0.0 : Wed Nov 30 2005 - 04:54:58 EST