• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL SELECT statement with strings?

 
Rui Ferns
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic