Or if you want it to work in any version of jdbc (and use ever so slightly less code):
 
if(rs.next()) {
  do {
    out.println("username " + rs.getString("username"));
  } while(rs.next());
} else {
  out.println("No record found");
}
 
  (*Chris*)
----- Original Message -----
Sent: Wednesday, January 30, 2002 10:29 PM
Subject: Re: [JSP-INTEREST] JDBC

or u can write
 
if (rs.next()) {
 rs.beforeFirst();
  while (rs.next()) {
    out.println("username " + rs.getString("username"));
  }
}
else {
  out.println("No record found");
}
 

Vikramjit Singh,
Systems Engineer,
GTL Ltd.
Ph. 7612929-3140

-----Original Message-----
From: Surya Narayana [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 30, 2002 10:37 PM
To: [EMAIL PROTECTED]
Subject: Re: JDBC

Hello Rama,
 
   You are using rs.next() twice. Thats why it is skipping the first record. Its enough to use rs.next() in while loop. no need of if loop.
 
Thanks & Regards,
 
Surya
 
----- Original Message -----
From: Rama
Sent: Thursday, January 31, 2002 11:53 AM
Subject: JDBC

Hi,

I wonder how to know if the query returned is empty or not.

I use this code:
ResultSet rs = stmt.executeQuery("SELECT * FROM user");

if (rs.next()) {
  while (rs.next()) {
    out.println("username " + rs.getString("username"));
  }
}
else {
  out.println("No record found");
}


but it always skips the first line of the record.

1. How to know if the query returned is empty or not.

2. Also, is there any way to know how many records returned?


Thank you,


Rama



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.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://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to