Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    28

    Unanswered: 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

  2. #2
    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!

  3. #3
    Join Date
    Dec 2003
    Posts
    28
    Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •