The Artima Developer Community
Sponsored Link

Java Answers Forum
how will i get total no of rows in the table..

9 replies on 1 page. Most recent reply: Sep 30, 2003 4:10 AM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 9 replies on 1 page
shailu

Posts: 2
Nickname: stylu
Registered: Sep, 2003

how will i get total no of rows in the table.. Posted: Sep 13, 2003 5:33 AM
Reply to this message Reply
Advertisement
hello again,
I am executing the query thro' jdbc calls..
I need to total no of rows without having to traverse thro' the entire table.
Hey i tried executin this, select count(*) ...
stmt.execute() returns me a result set not a number.
looking forward for answers,
With regards
stylu


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 13, 2003 6:00 AM
Reply to this message Reply
Afere execuiting the query select *.........

use resultSet.getInt(0);

Leela

Posts: 16
Nickname: leee
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 18, 2003 11:30 PM
Reply to this message Reply
mausam,

isnt it rs.getInt(1);

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: how will i get total no of rows in the table.. Posted: Sep 18, 2003 11:52 PM
Reply to this message Reply
it will be rs.getInt() if and only if rs has been defined as ResultSet that is

ResultSet rs = null; 

Leela

Posts: 16
Nickname: leee
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 19, 2003 1:54 AM
Reply to this message Reply
Actually what i meant was,

Statement stmt=conn.createStatement();//conn being the Connection Object
ResultSet rs = stmt.executeQuery("select count(*)......");

int count=rs.getInt(1); // instead of getInt(0);

This is because if u have a query like,

Select name,age,sal from employee

then ,
name will be rs.getString(1);
age=rs.getInt(2);

the indexing into the columns of the table starts from 1, and not 0.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: how will i get total no of rows in the table.. Posted: Sep 19, 2003 2:22 AM
Reply to this message Reply
I am sorry I misunderstood the intention of your post. At the same time I would like to point you to Charles Miller weblog where he has analyzed this inconsistency in Java where some indexes like List starts in zero{0} and ResultsSet index starts at one{1}.

Goto this URL

http://fishbowl.pastiche.org/archives/2003_02.html

and read the blog under "A foolish consistency" and let me know whether you find it interesting :-)

Leela

Posts: 16
Nickname: leee
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 19, 2003 3:06 AM
Reply to this message Reply
it is indeed interesting!!!!

i always wonder how do u manage to know abt all these sites.....

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 19, 2003 3:52 AM
Reply to this message Reply
Sorry ...i wrote rs.getInt(0); ??? did I??

Oh it were some aliens manipulating with my posting when I am gone......

Aliens I will catch u some day......

Leela

Posts: 16
Nickname: leee
Registered: Sep, 2003

Re: how will i get total no of rows in the table.. Posted: Sep 19, 2003 7:26 AM
Reply to this message Reply
HI mausam,
how can u leave ur login so vulnerable for the "aliens" to play.......
watch out!!

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: how will i get total no of rows in the table.. Posted: Sep 30, 2003 4:10 AM
Reply to this message Reply
The link I posted earlier was not working so let me post another here again...

http://fishbowl.pastiche.org/2003/02/10/a_foolish_consistency

Flat View: This topic has 9 replies on 1 page
Topic: Indian Editions Previous Topic   Next Topic Topic: populating a tree from a database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use