count no. of records resultset

Hi,I want to count number of records matches in query result. iam using jsp & ms access database. please tell some suggestions.RegardsChinna
[172 byte] By [chinnasamya] at [2007-11-26 20:19:07]
# 1

Interesting question,

Its very simple concept. Just using select query to fetch datas from the table.

And store in the resultset.

int n=0;

qry="select * from tablename"

statement st = db.executeQuery(qry);

Resultset rs=st.resultset();

while(rs.next)

{

n++;

}

out.println("The Number of record is"+n++);

azhar_sundeva at 2007-7-10 0:42:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for ur suggestions..i want to print no. of records found in the resultset before going to the while(rs.next){}. for example we can able to get no. columns found in the record using getColumnCount() method. so like that, is there any methods to find
chinnasamya at 2007-7-10 0:42:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
just do this select count(*) from tablenamei think this is simpler
G_Abubakra at 2007-7-10 0:42:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
hii have like this..rs = st.executeQuery("select company_name, product_description, product_summary, image_path, website from products where sub_catogery='"+product_catid+"'");In this where i can use count(*) in this query.RegardsChinna
chinnasamya at 2007-7-10 0:42:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

here is a simple answer:

int row_count = 0;

rs = st.executeQuery("select count(*) from products where sub_catogery='"+product_catid+"'");

if(rs.next())

{

row_count = rs.getInt(1);

}

rs = st.executeQuery("select company_name, product_description, product_summary, image_path, website from products where sub_catogery='"+product_catid+"'");

//rest of code

jloyd01a at 2007-7-10 0:42:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Thanks jloyd01 for your kindly help.RegardsChinna
chinnasamya at 2007-7-10 0:42:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...