If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > a simple question about count(*)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-04, 13:54
digital_storm digital_storm is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
a simple question about count(*)

Hello!
I'm using a javaBean to connect to Mysql.
I have got a table "tider" where I have a uniqe column called "key". I want to have the column indexed like 1,2,3,4,5 so I guess that I should use:
Statement selectStatement = con.createStatement();
String query = "SELECT COUNT(*) FROM tider";
ResultSet rs = selectStatement.executeQuery(query);

while (rs.next()) {

}

rs.close();
selectStatement.close();
con.close();
So I check the current numbers of rows and then add with one to get the uniqe index.

But how do I get the index? should I use rs.get(Something)() or?

Thanks for helping me! // D_S
Reply With Quote
  #2 (permalink)  
Old 01-22-04, 06:49
brianpower brianpower is offline
Registered User
 
Join Date: Jan 2004
Posts: 8
String query = "SELECT COUNT(*) as NumRecords FROM tider";
ResultSet rs = selectStatement.executeQuery(query);

if (rs.next()) {
int iNumRecords = rs.getInt("NumRecords");
}

rs.close();
selectStatement.close();

thats the way i do it anyway!
Reply With Quote
  #3 (permalink)  
Old 01-22-04, 07:03
digital_storm digital_storm is offline
Registered User
 
Join Date: Dec 2003
Posts: 28
Thank you very much!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On