Re: MySQL ResultSet - count rows?



Christoph wrote:
I am writing the data of a ResultSet object to an array. To declare
the array length, I need to know the number of rows before copying
them - is there a way to read the row count instantly, without having
to iterate anything?

PHP has mysql_count_rows, but I'm not sure what that does internally -
it may just iterate over the data too.

If you read the fine print in the PHP manual:

http://www.php.net/manual/en/function.mysql-num-rows.php

#Note: If you use mysql_unbuffered_query(), mysql_num_rows() will not
#return the correct value until all the rows in the result set have been
#retrieved.

You will see that it only return the the right number if you
either read all rows to memory with mysql_query or with
mysql_unbuffered_query have read all rows.

So in that sense PHP and JDBC are identical.

BTW, I agree completely with all those that have suggested
forgetting about the number and store the data in an
ArrayList.

Arne
.



Relevant Pages

  • Re: MySQL ResultSet - count rows?
    ... the array length, I need to know the number of rows before copying ... it may just iterate over the data too. ... At least incrementing the pointer is not a very expensive action. ...
    (comp.lang.java.databases)
  • Re: MySQL ResultSet - count rows?
    ... I am writing the data of a ResultSet object to an array. ... I need to know the number of rows before copying ... it may just iterate over the data too. ...
    (comp.lang.java.databases)
  • MySQL ResultSet - count rows?
    ... I am writing the data of a ResultSet object to an array. ... To declare ... I need to know the number of rows before copying ... it may just iterate over the data too. ...
    (comp.lang.java.databases)
  • Re: MySQL ResultSet - count rows?
    ... the array length, I need to know the number of rows before copying ... it may just iterate over the data too. ... Sabine Dinis Blochberger ...
    (comp.lang.java.databases)
  • Re: [ANN] Rio 0.3.4
    ... > Will a modification of IRB with RIO, and a few other things, possibly result ... >> Ways to get the chomped lines of a file into an array ... >> Iterate over only the files in a directory ... >> * New Grande Selection parameter. ...
    (comp.lang.ruby)