tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manuel Rodriguez Diaz" <mr...@ts.es>
Subject Re: ResultSet
Date Wed, 29 May 2002 07:29:54 GMT
Thankyou.
I've just tried this.
In fact i write a select count(1) which is faster (for a reason i don't know).
The problem is that in many cases i have a group clause that cause problems with
this method.
So i thought this:

resultset= statement.CreateQuery();
resultset2= resultset;

Obviously, both resultset and resultset2 points the same set of data.
Because i have java 1.1, my resultsets are forward-only. When i loop resultset
to count, resultset2 loops too.

I've tried to clone the resultset too.
    ResultSet temp;
    Object aux= new Object();
    aux= (java.lang.Object)rs;
    temp= (ResultSet)aux.clone();

But it fails at compilation time. What can i do?

James Mitchell escribió:

> have you tried getting the row count from the db instead of looping
> yourself?
>
> this approach will offload a few resources (counting) back to the db
> (assuming its tiered) where it belongs(IMHO)
>
> //assuming your db supports count() [duh]
> //if you build your sql in chunks
> String sqlSelect = "Select Col1, Col2 "
> String sqlFrom   = "From myTable "
> String sqlWhere  = "Where Col3 = 'SomeVal'";
>
> //typically a helper function
> //execute the sql on your connection
> Resultset rs = getMyResults("Select count(*) as ct " + sqlFrom + sqlWhere);
> size = rs.getLong("ct")
> //proceed as you did before, but this time you have the row count.
>
> Hope this helps.
>
> James Mitchell
>
> > -----Original Message-----
> > From: Manuel Rodriguez Diaz [mailto:mrodr@ts.es]
> > Sent: Tuesday, May 28, 2002 12:56 PM
> > To: tomcat-dev@jakarta.apache.org
> > Subject: ResultSet
> >
> >
> >
> > Hi all,
> > I'm working with java 1.1. (this is a mandatory requirement).
> > In this version of Java, resultset are "FORWARD ONLY".
> > The fact is that i need to count the rows contained in a resultset
> > before displaying its data and the  way i've thought to do this is read
> > all the resultset.
> > rows= 0;
> > while( rs.next()) {
> >     rows++;
> > }
> >
> > With my actual version of java, I would need to re-execute the query
> > again to get the pointer "beforeFirsted".
> > Is there any way to obtain a independent copy of a ResultSet without
> > executing the query again?
> >
> > Thankyou
> >
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message