File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem with SQL select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with SQL select" Watch "Problem with SQL select" New topic
Author

Problem with SQL select

shree vijay
Ranch Hand

Joined: Sep 18, 2000
Posts: 208
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


Regards,<BR>Shree
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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

Joined: May 10, 2000
Posts: 1913
    
    6
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

Joined: Sep 18, 2000
Posts: 208
Thanks,Simon, it was a small nuance but I definitely missed it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with SQL select