Solved

Query error (servlets, not jsp)

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

16 Experts available now in Live!

Get 1:1 Help Now