Solved

Query error (servlets, not jsp)

Posted on 2004-08-05
4
244 Views
Last Modified: 2010-04-01
I couldn't find a servlets section, so this was my best bet.  Here is my problem:

I have the following code:

while(rset.next())  //rset from rset = stmt.executeQuery(nameQuery);
{
     //imagine all this on one line
     out.println("<a href= \"http://localhost:8080/servlet/helpdesk.CustomerDetails?
     CustName=" + rset.getString(1) + "\">" + rset.getString(1) + "</a><br>");
}

I am trying to do a db search and the results are printed out in hyperlinks as listed above.  So a link might look like:

http://localhost:8080/servlet/helpdesk.CustomerDetails?CustName=Visa
http://localhost:8080/servlet/helpdesk.CustomerDetails?CustName=Microsoft

However, when I do my search I get the following error:

executeQuery No data found

Here's the tricky part.  If I declare a variable String test = "test" and replace the first rset.getString(1) with test, the search works and i get hyperlinks that look like:

http://localhost:8080/servlet/helpdesk.CustomerDetails?CustName=test
http://localhost:8080/servlet/helpdesk.CustomerDetails?CustName=test

Any tips?
0
Comment
Question by:ike2010
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 250 total points
ID: 11728659
It may not allow to call rset.getString(1)  two times.
Fix this by assign the getString to String variable before use.

String temp = rset.getString(1);

out.println("<a href= \"http://localhost:8080/servlet/helpdesk.CustomerDetails?
     CustName=" + temp + "\">" + temp + "</a><br>");
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11728693
Don't forget to URLEncode temp in the href part...

String temp = rset.getString(1);
out.println("<a href= \"http://localhost:8080/servlet/helpdesk.CustomerDetails?CustName=" + java.net.URLEncoder.encode( temp, "UTF-8" ) + "\">" + temp + "</a><br>");
0
 

Author Comment

by:ike2010
ID: 11728965
Thanks sompol.  I don't know why this is the case because I have used my original solution before.  Of course that was using an ORACLE server and now I'm using MS SQL Server, so maybe that has something to do with it.
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11732029
I think it depends on driver you use.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
This problem is more common than not and I will show you some things to check to solve this problem.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

832 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