Solved

find USERID error in JSP

Posted on 2006-07-03
2
363 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now