• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic