Link to home
Start Free TrialLog in
Avatar of ike2010
ike2010

asked on

Query error (servlets, not jsp)

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?
ASKER CERTIFIED SOLUTION
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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>");
Avatar of ike2010
ike2010

ASKER

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.
I think it depends on driver you use.