🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.sqlinfo
Article #343

Re: Count in SQL...

#343
From: bnaranapatti
Date: Thu, 07 Oct 1999 00:00
47 lines
1870 bytes
Hi,
 This should work :
 PreparedStatement ps = connection.prepareStatement("SELECT COUNT(*)
FROM MyTable");
 ps.executeQuery();
 rs = ps.getResultSet();
 long aCount = 0L;
 if (rs.next()) {
   aCount = rs.getLong(1);
 }

 where aCount would be the number of records you are looking for.

Happy JDBCing

Balaji
In article <uRhK3.4157$lE.22937@ozemail.com.au>,
  "Gavin Wong" <gavinthwong@ozemail.com.au> 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.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID: <7tj91a$ftd$1@nnrp1.deja.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <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: bnaranapatti@my-deja.com
Subject: Re: Count in SQL...
Date: 1999/10/07
Message-ID: <7tj91a$ftd$1@nnrp1.deja.com>
X-Deja-AN: 534074382
References: <uRhK3.4157$lE.22937@ozemail.com.au>
X-Http-Proxy: 1.1 x29.deja.com:80 (Squid/1.1.22) for client 167.158.206.74
Organization: Deja.com - Before you buy.
X-Article-Creation-Date: Thu Oct 07 23:06:27 1999 GMT
X-MyDeja-Info: XMYDJUIDbnaranapatti
Newsgroups: bit.listserv.sqlinfo
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)