Solved

Query error (servlets, not jsp)

Posted on 2004-08-05
4
247 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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
Apache-Tomcat Single Sign On with NTLM/Kerberos on Windows 2008R2 3 229
library class in java 1 93
tomcat users xml 7 127
Clear browser cache on site login, is it possible? 3 31
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 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