• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

SQL SELECT statement with strings?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a page where a user fills in a form field.
When they hit submit the page is sent to a database checker page where I want to retrieve all rows in the table containing the string the user entered in the form field. I'm not sure how to write this SELECT statement.
I get this error when I hit the submit button:
"javax.servlet.ServletException: [Microsoft][ODBC Microsoft Access 97 Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"
Heres the part of my code:
Basically I want to retrieve all the rows containing the string the user entered in the form field.
=================================================================
<%
if((request.getParameter("KenSearch")) != null)
{
String index = request.getParameter("KenwoodChoice");
PreparedStatement pstmt = conn.prepareStatement("SELECT FROM PRODUCTS WHERE DESC = (?)");
pstmt.clearParameters();
pstmt.setString(1, index);
ResultSet rs = pstmt.executeQuery();
}
=================================================================
Thanks
Rui
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should be "SELECT * FROM PRODUCTS WHERE DESC = (?)".
Also try to name the vars meaningfully. "String index" looks somewhat odd in my humble opinion.
regds
maha anna
 
Rui Ferns
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks got it working.
That was a silly mistake.
I'm using index cause it is a value of 1 of 10 submit buttons.
Its lets me know which one I clicked on.
Thanks for the help.
Rui
 
Evil is afoot. But this tiny ad is just an ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic