wood burning stoves 2.0*
The moose likes Servlets and the fly likes SQL SELECT statement with strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SQL SELECT statement with strings?" Watch "SQL SELECT statement with strings?" New topic
Author

SQL SELECT statement with strings?

Rui Ferns
Greenhorn

Joined: May 06, 2001
Posts: 24
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

Joined: Jan 31, 2000
Posts: 1467
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

Joined: May 06, 2001
Posts: 24
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL SELECT statement with strings?
 
Similar Threads
'Syntax Error in Query operator' MS Access
Error attempting to submit data via a form
Unable to update database
Embed form element value in scriplet?
Retaining values between JSP pages