signoff
-----Original Message-----
From: sunil_s23 [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 18, 2001 9:48 AM
To: [EMAIL PROTECTED]
Subject: Re: Checking for Empty Result Set
Thanks Mihir, it worked.
Thanks to Ron and all others also.
And Maurice, what can I tell you about your
comments :-) ?
Sunil.
--- Mihir Sahu <[EMAIL PROTECTED]> wrote:
> Hi,
> Remove the if statement. Just declare a boolean
> before the while and set it to
> false. Inside the while statement, just set it to
> true. To check if empty set,
> check the value of the boolean after the while. If
> it is true, then it is not
> empty else its empty. It does not do any overheads
> or any performance
> degradation. Thank
> Regards
> Mihir
>
> sunil_s23 wrote:
>
> > If we consider a large application; this involves
> > doubling the number of SQL queries; one extra
> query
> > for each query just to find out the count; I feel
> that
> > we should be considering the overheads in
> accessing a
> > database and executing a query and that too if it
> is
> > over a network with heavy traffic.....
> >
> > --- King Maurice <[EMAIL PROTECTED]> wrote:
> > > Economical way, your right its kinda tedious,
> but it
> > > only about 4 simple
> > > lines of code, how economical can you get, just
> pure
> > > laziness maybe, but
> > > that is up to your discretion, as long as you
> get
> > > the job done.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "sunil_s23" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Monday, June 18, 2001 12:07 PM
> > > Subject: Re: Checking for Empty Result Set
> > >
> > >
> > > > That calls for two sql statements; is there a
> more
> > > > economical way out ?.
> > > > The following code seems to work, but not
> always.
> > > > Any pointers ?
> > > >
> > > > ResultSet rs = ps.executeQuery();
> > > > if(rs.isBeforeFirst() == false)
> > > > {
> > > > System.out.println("empty result set");
> > > > }
> > > > else
> > > > {
> > > > while(rs.next())
> > > > {
> > > >
> > > >
> System.out.println(rs.getString("EMPLOYEE_NAME"));
> > > > }
> > > > }
> > > >
> > > > --- King Maurice <[EMAIL PROTECTED]>
> wrote:
> > > > > Well the get the count of the resultset in
> your
> > > sql
> > > > > command and then test
> > > > > for a condition of one
> > > > >
> > > > > You need to figure out on your own, the
> > > conditions
> > > > > in your code, if not your
> > > > > lost!!!!
> > > > >
> > > > > Maurice~
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "sunil_s23" <[EMAIL PROTECTED]>
> > > > > To: <[EMAIL PROTECTED]>
> > > > > Sent: Monday, June 18, 2001 11:58 AM
> > > > > Subject: Re: Checking for Empty Result Set
> > > > >
> > > > >
> > > > > > This definitely caters to the case when
> there
> > > is
> > > > > only
> > > > > > one row in the result set; but what about
> the
> > > case
> > > > > if
> > > > > > the result set contains more than one row.
> I
> > > am
> > > > > > looking for a solution which will handle
> both
> > > > > single
> > > > > > row results and multiple row results as
> well
> > > as
> > > > > the
> > > > > > case when the result set is empty.
> > > > > > Any suggestions ?,
> > > > > > Thanks,
> > > > > > Sunil.
> > > > > >
> > > > > > --- King Maurice
> <[EMAIL PROTECTED]>
> > > wrote:
> > > > > > > I see your problem
> > > > > > >
> > > > > > > Do this example or follow this example
> if
> > > you
> > > > > can
> > > > > > > comprehend.
> > > > > > >
> > > > > > > Example below::
> > > > > > >
> > > > > > > if (! rs.next())
> > > > > > > {
> > > > > > > %>
> > > > > > > <table><tr><td>empty result
> > > > > set</td></tr></table>
> > > > > > > <%
> > > > > > > }
> > > > > > > else
> > > > > > > {
> > > > > > > String employee =
> > > > > rs.getString("EMPLOYEE_NAME"));
> > > > > > > %>
> > > > > > > <table><tr><td><%= employee
> > > > > %></td></tr></table>
> > > > > > > <%
> > > > > > > }
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > ----- Original Message -----
> > > > > > > From: "sunil_s23" <[EMAIL PROTECTED]>
> > > > > > > To: <[EMAIL PROTECTED]>
> > > > > > > Sent: Monday, June 18, 2001 11:44 AM
> > > > > > > Subject: Re: Checking for Empty Result
> Set
> > > > > > >
> > > > > > >
> > > > > > > > See the code below, it does not work
> if
> > > there
> > > > > is a
> > > > > > > > single row in the result set; in other
> > > words
> > > > > the
> > > > > > > > statement if(!rs.next()) causes a row
> of
> > > > > result
> > > > > > > set to
> > > > > > > > be skipped.
> > > > > > > > Any suggestions ?,
> > > > > > > > Sunil.
> > > > > > > >
> > > > > > > > ResultSet rs =
> ps.executeQuery();
> > > > > > > > if(!rs.next())
> > > > > > > > System.out.println("empty
> > > result
> > > > > > > set");
> > > > > > > > while(rs.next())
> > > > > > > > {
> > > > > > > >
> > > System.out.println(rs.getString
> > > > > > > > ("EMPLOYEE_NAME"));
> > > > > > > > }
> > > > > > > >
> > > > > > > > --- Satyanarayan Divakar
> > > > > > > > <[EMAIL PROTECTED]>
> wrote:
> > > > > > > > > if(!resultSet.next())
> > > > > > > > > display"No Records Retreived";
> > > > > > > > >
> > > > > > > > > -----Original Message-----
> > > > > > > > > From: sunil_s23
> > > [mailto:[EMAIL PROTECTED]]
> > > > > > > > > Sent: Monday, June 18, 2001 10:27 AM
> > > > > > > > > To: [EMAIL PROTECTED]
> > > > > > > > > Subject: Re: Checking for Empty
> Result
> > > Set
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > Hi All,
> > > > > > > > > A ResultSet is never null once we
> > > execute a
>
=== message truncated ===
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets