Article View: bit.listserv.sqlinfo
Article #346Re: Count in SQL...
From: Robert Larsen
Date: Sun, 10 Oct 1999 00:00
Date: Sun, 10 Oct 1999 00:00
32 lines
1738 bytes
1738 bytes
When only using the COUNT funktion, you only get one result. The result of the
count, whether it is 0 or not.
You could do this:
ResultSet rs = stmt.executeQuery("SELECT COUNT(BSBNO) FROM Mytable");
rs.next();
int numbers=rs.getInt(1);
I hope that answers your question.
Gavin Wong wrote:
> Dear all,
> Could you please tell me how to get the number of records in my database by
> using the COUNT sql statement?
> Let's say i have a Table call Mytable, the table contains two columns which
> are BSBNO and NAME. I would like to know how many BSBNO(of type int) records
> have been stored in my Mytable. So that i wrote the following statement in
> my Java JDBC program:
>
> ResultSet rs = stmt.executeQuery("SELECT COUNT(BSBNO) FROM Mytable");
> while (rs.next()) { what should i write here??}
>
> Shall i set:
> int n = ResultSet rs = stmt.executeQuery("SELECT COUNT(BSBNO) FROM
> Mytable"); ?? can i?
> i need to know what's the value of "n".
> Please help..Thanks.
>
> with regards,
> gavin.
Technical Details
Message-ID:
<3800B093.368DDF7B@ah.dk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<uRhK3.4157$lE.22937@ozemail.com.au>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11355a,92a65899ed85587c X-Google-Attributes: gid11355a,public From: Robert Larsen <dm29q@ah.dk> Subject: Re: Count in SQL... Date: 1999/10/10 Message-ID: <3800B093.368DDF7B@ah.dk> X-Deja-AN: 535031234 Content-Transfer-Encoding: 7bit References: <uRhK3.4157$lE.22937@ozemail.com.au> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@telia.dk X-Trace: news101.telia.com 939569413 3665 194.255.245.166 (10 Oct 1999 15:30:13 GMT) Organization: Customer at Telia Danmark (http://www.telia.dk/) Mime-Version: 1.0 NNTP-Posting-Date: 10 Oct 1999 15:30:13 GMT Newsgroups: bit.listserv.sqlinfo