Solved

find USERID error in JSP

Posted on 2006-07-03
2
369 Views
Last Modified: 2010-08-05
hi experts,

I have jsp which call itself and check certain condition and displays record. If I search by userid, it shows me correct record
<%
if (request.getParameter.equals("Y"))
{
  String getUserId = request.getParameter("userid");
...
..
sb.append(" AND UPPER(USERID) LIKE UPPER('"+getUserId+any+"')");
...
..
rs= stmt.executeQuery(sb.toString());
..
while (rs.next())
 {
...
 }
}
%>

worked fine. Now I added condition if no userid exist display msg. "No users to display". If I type wrong ID it does display msg. But when I type correct ID I'm not getting the record display nor do I'm getting error. Seems like logic error after adding that if (!rs.next())

<%
if (request.getParameter.equals("Y"))
{
  String getUserId = request.getParameter("userid");
...
..
sb.append(" AND UPPER(USERID) LIKE UPPER('"+getUserId+any+"')");
...
..
rs= stmt.executeQuery(sb.toString());
..
if(!rs.next())
        {
          out.print("No users to display");                
        }  
while (rs.next())
 {
...
 }
}
%>


Thx.
PH
0
Comment
Question by:princehyderabad
2 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 100 total points
ID: 17033092
Does the SQL return only one row? If yes, then will not go into the while loop, since for each call of rs.next(), the cursor of the resultset will advance to next record, and if there is no more record, it will return false.

One way is to do this:

boolean hasUser = false;

while (rs.next()) {
     // do whatever
     hasUser = true;
}

if (!hasUser)
   out.print("No users to display");
0
 

Author Comment

by:princehyderabad
ID: 17033106
It returns ONE row if userID matchs exactly the same. But if I search for userID 'a'  all userID starting with 'a' will be displayed. If I search "XYZ" then only one row is return where userId=XYZ
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JSP Popup page 2 137
EJB MDB example 4 87
Java Exception example issues 11 84
mask rule in struts validation.xml 5 94
Read about why it is more lucrative for an IT company to participate in government projects.
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question