Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old October 10th, 2002, 01:44 PM
alka205 alka205 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 14 alka205 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Number of rows in the select statement

I am doing a select select statement through JSP. I wan't to give number of rows in the result...

For eg..

String s1 = "SELECT id, f_name,l_name FROM login WHERE username = '"+ username +" '";
I want to display the number of rows returned....

How do I do that....

I tried...
int rowsUpdated1 = theStatement.executeSelect(s1);

got the following error....

Can't convert java.sql.ResultSet to int.

Reply With Quote
  #2  
Old October 10th, 2002, 02:15 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
i don't know of any member functions to do this, but this should work:
Code:
public int getNumRows(ResultSet rs) {
    int numRows = 0;     
    while(rs.next()) {
        numRows++;
    }
    return numRows;
}

Reply With Quote
  #3  
Old October 10th, 2002, 02:47 PM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Ya, I don't see anything either.

One thing you could do is add something like "count(*) as rsSize" to your sql, then get the value out of the ResultSet. This is probably faster than counting the rows.

Reply With Quote
  #4  
Old October 10th, 2002, 03:24 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Number of rows in the select statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway