Re: MySQL ResultSet - count rows?



Hi Christoph

as others already pointed out, there is SELECT COUNT (*). The advantage
of that is that the counting can be done in the DB instead of sending
all records from the DBto your app.
But, as you want to read all records anyway, why not store them in a
Java collection (say a List), and use .toArray() to get an array out
of the collection? That way the data has to be fetched only once, and
you need only one DB call.

HTH
Guido

Christoph schrieb:
Hello,

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.

--
Chris
.



Relevant Pages

  • Re: finding most common elements between thousands of multiple arrays.
    ... the elements are initially held in a array within an array. ... but with my algorithm that only takes about ... times and it seems silly to iterate through 2 million things just to ... you can just iterate over the large array counting as you go; ...
    (comp.lang.python)
  • 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)
  • [ANN] Rio 0.3.4
    ... Rio is a Ruby I/O convenience class wrapping much of the functionality ... Copy or append a file to a string ... Ways to get the chomped lines of a file into an array ... Iterate over only the files in a directory ...
    (comp.lang.ruby)
  • [ANN] Rio 0.3.7
    ... Rio is a Ruby I/O convenience class wrapping much of the functionality ... Copy or append a file to a string ... Ways to get the chomped lines of a file into an array ... Iterate over only the files in a directory ...
    (comp.lang.ruby)
  • [ANN] Rio 0.4.1
    ... = Rio - Ruby I/O Facilitator ... Iterate over the .rb files in a directory and its subdirectories. ... Return an array of the .rb files in a directory and its ... Copy or append a file to a string ...
    (comp.lang.ruby)