Solved

find USERID error in JSP

Posted on 2006-07-03
2
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Learn why we support net neutrality and why the topic is important to all internet users.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 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