jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Select query based on userinput Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Select query based on userinput" Watch "Select query based on userinput" New topic

Select query based on userinput

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi Folks...

I am trying to make a select query based on a user input. Earlier I was having probelms making a select query and printing out the result in the stack trace,with the advice given here, I managed to solve that. I am now modifying that code to make a query based on user input, however it's not working, following is the code:

stack trace seems to suggest I may have a probelm with this statement:

I am not sure how to rectify this, I hope someone can advise, thanks.

Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
You're preparing the SQL statement, then setting the first parameter, but that is not what you're executing on the executeQuery. Have a look at the java.sql API.
You're actually calling the inherited method java.sql.Statement.executeQuery(String) with an incompleted SQL string when you probably want to call java.sql.PreparedStatement.executeQuery() given that you went through the trouble of preparing it and setting the parm.

Hope this helps.
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi Ed Ward...

Thanks for the message, I appreciate it. I have managed to solve the problem based on your advise and also from this site. I only made one change...


was changes to this:

Thanks once again..

I agree. Here's the link: http://aspose.com/file-tools
subject: Select query based on userinput
It's not a secret anymore!