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 : Mon Nov 28 2005 - 09:39:22 EST