• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with SQL select

 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • 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
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks,Simon, it was a small nuance but I definitely missed it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic