Re: ResultSet
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:[EMAIL PROTECTED]] Sent: Tuesday, May 28, 2002 12:56 PM To: [EMAIL PROTECTED] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: ResultSet
Manuel, For you to be able to invoke the clone() method on an Object does'nt it have to implement Cloneable interface. That's the reason why to are getting a compile time error. If JDK is not a constraint you can switch to 1.2 or 1.3.x and use CachedRowSet which allow you to have bidirectional. Another programmatic approach would be when you are iterating through the rows to count the rows push all the data in each row into a data model that mimics each row in the table and keep adding them in an Array of some sort. Of course if you don't want to do this...then solution to do select count(*)... would be the option I would go with. Anand -Original Message- From: Manuel Rodriguez Diaz [mailto:[EMAIL PROTECTED]] Sent: Wednesday, May 29, 2002 1:00 PM To: Tomcat Developers List Subject: Re: ResultSet 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:[EMAIL PROTECTED]] Sent: Tuesday, May 28, 2002 12:56 PM To: [EMAIL PROTECTED] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: ResultSet
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:[EMAIL PROTECTED]] Sent: Tuesday, May 28, 2002 12:56 PM To: [EMAIL PROTECTED] 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:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: ResultSet
Try to do this: if ((res.getString(3) != null) (res.getString(3).length 0)) { ... } It is because java.util.String must use its equals() method for string comparison. The only logical operator you can use is for null comparison. Also some database distinguish between empty string '' and null value, just becareful of that! -Original Message- From: Paul Wallace [SMTP:[EMAIL PROTECTED]] Sent: Monday, March 11, 2002 3:58 AM To: Tomcat Developers List Subject: ResultSet Hi, For the brave, can anyone guess why with this rather unsociable code: if ((res.getString(3) == null) || (res.getString(3) == )) { out.println(tda href=takeDetails.jsp?timeSlot= + res.getString(2) + myDate= + myDate + + res.getString(2) + /a/td); } if ((res.getString(3) != null) || (res.getString(3) != )) { out.println(td + res.getString(3)+ + res.getString(2) + /td); } the first condition is NEVER satisfied, even though out.println of res.getString(3) does not display anything! Ie res.getString(3) IS null, empty or whatever, but the condition is never satisifed. Quickly again, this is executed: if ((res.getString(3) != null) || (res.getString(3) != )) { out.println(td + res.getString(3)+ + res.getString(2) + /td); } even though - out.println(td + res.getString(3)+ - shows it is empty (no output)! Thanks Paul. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: ResultSet
If you want to compare String objects as literals, use the intern() method. Micael At 03:58 PM 3/11/02 +0700, you wrote: Hi, For the brave, can anyone guess why with this rather unsociable code: if ((res.getString(3) == null) || (res.getString(3) == )) { out.println(tda href=takeDetails.jsp?timeSlot= + res.getString(2) + myDate= + myDate + + res.getString(2) + /a/td); } if ((res.getString(3) != null) || (res.getString(3) != )) { out.println(td + res.getString(3)+ + res.getString(2) + /td); } the first condition is NEVER satisfied, even though out.println of res.getString(3) does not display anything! Ie res.getString(3) IS null, empty or whatever, but the condition is never satisifed. Quickly again, this is executed: if ((res.getString(3) != null) || (res.getString(3) != )) { out.println(td + res.getString(3)+ + res.getString(2) + /td); } even though - out.println(td + res.getString(3)+ - shows it is empty (no output)! Thanks Paul. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]