Re: MySQL ResultSet - count rows?



On Dec 10, 10:34 am, Dyreatn...@xxxxxxx wrote:
Christoph <christoph.bursc...@xxxxxxxxx> writes:
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?

No. You could execute 'SELECT COUNT(*) ...' first but then you
essentially traverse all the rows twice.

(There could be non-standard MySQL extensions that lets you do this, I
don't know)



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

--
dt

Questions about Derby/Java DB? Please visithttp://db.apache.org/derby/derby_mail.html


Okay, I'm working around it by using

while(result.next()) rowcount++;

At least incrementing the pointer is not a very expensive action. Even
when I get a few thousand results back (which I will) the counting
will take far less time than the copying and instance creation that
follows.
.



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. ... So in that sense PHP and JDBC are identical. ...
    (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: A portion of long data bytes as a property
    ... copying the array isn't really that big of a problem most of the time; usually that copy is going to be sent off somewhere that is WAY slower than memory access. ... byteEntireData; ... actionUse(EntireBody, HeaderSize, EntireSize - HeaderSize); ...
    (microsoft.public.dotnet.languages.csharp)