?
Solved

find USERID error in JSP

Posted on 2006-07-03
2
Medium Priority
?
374 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 400 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

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

764 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