Re: Is there any way to check # of Records in RecordSet
Adam Buglass wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] A faster aproach if you are using TYPE_SCROLL_INSENSITIVE is to call rs.last() then call rs.getRow() I use this all the time and have not had any problems as of yet. To get back to the beginning is to then call rs.beforeFirst() then begin using as usual. Hope that helps. Wade - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there any way to check # of Records in RecordSet
Adam Buglass wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] A faster aproach if you are using TYPE_SCROLL_INSENSITIVE is to call rs.last() then call rs.getRow() I use this all the time and have not had any problems as of yet. To get back to the beginning is to then call rs.beforeFirst() then begin using as usual. Hope that helps. Wade - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE: Is there any way to check # of Records in RecordSet
== Date: 20 May 2004 17:45:23 +0100 From: Adam Buglass [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Subject: RE: Is there any way to check # of Records in RecordSet == I was just surprised because I've never run into that behaviour before and I've never changed the defaults. I'm sure you're right though, I probably set some global variable somewhere and forgot about it! Mmmhhh... global variable? What is global variable? ;-))) G -- Giuseppe Briotti [EMAIL PROTECTED] Alme Sol, curru nitido diem qui promis et celas aliusque et idem nasceris, possis nihil urbe Roma visere maius. (Orazio) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Is there any way to check # of Records in RecordSet
Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Any opinions expressed in this E-mail may be those of the individual and not necessarily the company. This E-mail and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivering to the intended recipient, be advised that you have received this E-mail in error and that any use or copying is strictly prohibited. If you have received this E-mail in error please notify the beCogent postmaster at [EMAIL PROTECTED] Unless expressly stated, opinions in this email are those of the individual sender and not beCogent Ltd. You must take full responsibility for virus checking this email and any attachments. Please note that the content of this email or any of its attachments may contain data that falls within the scope of the Data Protection Acts and that you must ensure that any handling or processing of such data by you is fully compliant with the terms and provisions of the Data Protection Act 1984 and 1998. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there any way to check # of Records in RecordSet
ResultSet rs; int i = 0; while( rs.next() ) { i++; } If the cursor is non scrollable, this will only work once. It is better for you to execute a Select count(1) ... query, to find out how many results you would get back. Or even better, execute a stored procedure that returns the count as an out variable, and the result set as another out variable Filip - Original Message - From: Adam Buglass [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Thursday, May 20, 2004 9:31 AM Subject: RE: Is there any way to check # of Records in RecordSet This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there any way to check # of Records in RecordSet
On Thu, May 20, 2004 at 03:26:25PM +0100, Dale, Matt wrote: : This is the wrong list i'm pretty sure but there are a couple of ways to get : the number but there isnt a direct method that returns it. : : If the result set is scrollable you can iterate through it counting the number : of iterations, then set it back to the start when you want to process the : records. If I can stand a second trip to the DB: select COUNT(*) from {...rest of query here...} then, perform the normal query. This is great for when you are going to pull back a subset of records, e.g. to display X of Total records per page. Slight risk of a race condition if the data's volatile, but... -QM -- software -- http://www.brandxdev.net tech news -- http://www.RoarNetworX.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
The first code will work if when you create your statement object you define it as scrollable. Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:50 To: Tomcat Users List Subject: RE: Is there any way to check # of Records in RecordSet Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Any opinions expressed in this E-mail may be those of the individual and not necessarily the company. This E-mail and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivering to the intended recipient, be advised that you have received this E-mail in error and that any use or copying is strictly prohibited. If you have received this E-mail in error please notify the beCogent postmaster at [EMAIL PROTECTED] Unless expressly stated, opinions in this email are those of the individual sender and not beCogent
Re: Is there any way to check # of Records in RecordSet
first code = result set not scrollable, you can only loop through it once Filip; - Original Message - From: soh_mah [EMAIL PROTECTED] To: Tomcat Users List [EMAIL PROTECTED] Sent: Thursday, May 20, 2004 9:50 AM Subject: RE: Is there any way to check # of Records in RecordSet Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
Please dont use for other than stated purpose of the list. I hope you understand that. -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: Thursday, May 20, 2004 10:50 AM To: Tomcat Users List Subject: RE: Is there any way to check # of Records in RecordSet Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Is there any way to check # of Records in RecordSet
First of all forgive me for being very stressed and tired - All I did was put into some kind of code model a suggestion previously put forward by Matt: If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. Second, I'm not sure whay Filip thinks it would only work once. Surely you could put it in a method and call that method over again - Just make sure you set it back to the start of the ResultSet each time! (I may well be missing something here - please don't hesitate to point it out!): If the cursor is non scrollable, this will only work once. However I do like the suggestion of getting it from the Database via a new query. You should avoid too many loops in code (especially While loops) - I'm afraid my SQL isn't quite what it should be! I'm assuming your HTML output is also set for the first option? Assuming the function is successful, you should be able to use %=count% in your HTML. If I know the precise list I would have given it to you! As I said, go check on Sun's java site (http://java.sun.com ??) and look for an appropriate messageboard on there, I think that's your best bet! On Thu, 2004-05-20 at 15:50, soh_mah wrote: Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway, Department of Child Health, University of Newcastle-upon-Tyne. Royal Victoria Infirmary. (0191) 2023062 Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote. ~Benjamin Franklin, 1759 - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] = Regards Sohail
RE: Is there any way to check # of Records in RecordSet
Adam - I mentioned this in another post but unless the result set is scrollable then you can't reset it back to the beginning. You need to declare the statement object as scrollable when you create it to achieve this. So Filip was right in that it will only work once with the default behaviour. -Original Message- From: Adam Buglass [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 16:02 To: Tomcat Users List Subject: RE: Is there any way to check # of Records in RecordSet First of all forgive me for being very stressed and tired - All I did was put into some kind of code model a suggestion previously put forward by Matt: If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. Second, I'm not sure whay Filip thinks it would only work once. Surely you could put it in a method and call that method over again - Just make sure you set it back to the start of the ResultSet each time! (I may well be missing something here - please don't hesitate to point it out!): If the cursor is non scrollable, this will only work once. However I do like the suggestion of getting it from the Database via a new query. You should avoid too many loops in code (especially While loops) - I'm afraid my SQL isn't quite what it should be! I'm assuming your HTML output is also set for the first option? Assuming the function is successful, you should be able to use %=count% in your HTML. If I know the precise list I would have given it to you! As I said, go check on Sun's java site (http://java.sun.com ??) and look for an appropriate messageboard on there, I think that's your best bet! On Thu, 2004-05-20 at 15:50, soh_mah wrote: Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Adam Buglass, The Golden Freeway,
RE: Is there any way to check # of Records in RecordSet
On Thu, 2004-05-20 at 16:38, Dale, Matt wrote: Adam - I mentioned this in another post but unless the result set is scrollable then you can't reset it back to the beginning. You need to declare the statement object as scrollable when you create it to achieve this. So Filip was right in that it wi Matt, yes you did I just didn't get it until after I'd sent mine! I was just surprised because I've never run into that behaviour before and I've never changed the defaults. I'm sure you're right though, I probably set some global variable somewhere and forgot about it! -Original Message- From: Adam Buglass [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 16:02 To: Tomcat Users List Subject: RE: Is there any way to check # of Records in RecordSet First of all forgive me for being very stressed and tired - All I did was put into some kind of code model a suggestion previously put forward by Matt: If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. Second, I'm not sure whay Filip thinks it would only work once. Surely you could put it in a method and call that method over again - Just make sure you set it back to the start of the ResultSet each time! (I may well be missing something here - please don't hesitate to point it out!): If the cursor is non scrollable, this will only work once. However I do like the suggestion of getting it from the Database via a new query. You should avoid too many loops in code (especially While loops) - I'm afraid my SQL isn't quite what it should be! I'm assuming your HTML output is also set for the first option? Assuming the function is successful, you should be able to use %=count% in your HTML. If I know the precise list I would have given it to you! As I said, go check on Sun's java site (http://java.sun.com ??) and look for an appropriate messageboard on there, I think that's your best bet! On Thu, 2004-05-20 at 15:50, soh_mah wrote: Thanks Adam :) First of all I subscribe to the list yesterday and I m new to JSP. Secondly could u plz tell me right list name so I can subscribe to that. Adam, I did exactly the same way u mentioned, but when I use like //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } rs.first(); //- it does not show me any thing on the page but when I use like this it shows me all records. //--- ResultSet rs = stmt.executeQuery(query); while(rs.next()) { count1++; } ResultSet rs1 = stmt.executeQuery(query); while{rs1.next()) { % Here is HTML % out.println(rs.getInt(first_column)); } % //- Then it shows me all the records, what is wrong with my first code? --- Adam Buglass [EMAIL PROTECTED] wrote: This is the wrong list but never mind An alternative is the following: ResultSet rs; int i = 0; while( rs.next() ) { i++; } The integer i should be the length of your result set (by the way, don't get confused with RecordSets which are VB - I used to do that all the time!) at the end of the loop - assuming of course that you start from the start of the set, you could use rs.first() to ensure this. There's tons of useful info on Java methods and classes on suns site: http://java.sun.com/j2se/1.3/docs/api/ http://java.sun.com/j2se/1.3/ Also look on www.sun.com for good java mailing lists where this kind of question is more specific. Adam. On Thu, 2004-05-20 at 15:26, Dale, Matt wrote: This is the wrong list i'm pretty sure but there are a couple of ways to get the number but there isnt a direct method that returns it. If the result set is scrollable you can iterate through it counting the number of iterations, then set it back to the start when you want to process the records. The other option (one I prefer) is to load the records into an ArrayList, you can then determine the size quite easily. If anyone else has any neater solutions i'd like to hear them too as I've had to do this in a few places. Ta Matt -Original Message- From: soh_mah [mailto:[EMAIL PROTECTED] Sent: 20 May 2004 15:20 To: [EMAIL PROTECTED] Subject: Is there any way to check # of Records in RecordSet Hi Is there any way to check number of Records in RecordSet? = Regards Sohail Mahmood (416) 636-2553 __ Do you Yahoo!? Yahoo! Domains - Claim yours for only $14.70/year http://smallbusiness.promotions.yahoo.com/offer