Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Query error (servlets, not jsp)

Posted on 2004-08-05
4
Medium Priority
?
267 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
[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
4 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 1000 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
An overview of cyber security, cyber crime, and personal protection against hackers. Includes a brief summary of the Equifax breach and why everyone should be aware of it. Other subjects include: how cyber security has failed to advance with technol…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

598 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