• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Problem with SQL select

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Here is a portion of my code:


In the location denoted by ****** in the SQL statement, I used findkey variable. This caused an error, I guess the SQL statement does not recognize the java variable. I also tried r.getString("user_Name") where r is my resultset. That didn't work too. I tried enclosing r.getString("user_Name") within <%= %> since this code is from a jsp file. That doesn't work too. What should I do?
------------------
Regards,
Shree
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I can see what you're asking ... have you tried the following?
ResultSet r=s.executeQuery("SELECT user_Name FROM user_Details WHERE user_Name = " + findKey);
instead of
ResultSet r=s.executeQuery("SELECT user_Name FROM user_Details WHERE user_Name = *******");
Regards
Simon
------------------
Simon Brown
Co-author of Professional JSP 2nd Edition
 
Simon Brown
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or, if user_name is a String on the database, you might need to do the following (notice the extra ' characters)...
ResultSet r=s.executeQuery("SELECT user_Name FROM user_Details WHERE user_Name = "'" + findKey + "'");

Originally posted by Simon Brown:
ResultSet r=s.executeQuery("SELECT user_Name FROM user_Details WHERE user_Name = " + findKey);


------------------
Simon Brown
Co-author of Professional JSP 2nd Edition
 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,Simon, it was a small nuance but I definitely missed it.
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic