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 SQL SELECT statement with strings? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL SELECT statement with strings?