This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Select query based on userinput" Watch "Select query based on userinput" New topic
Author

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...

this:


was changes to this:


Thanks once again..

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Select query based on userinput
 
Similar Threads
Unique datatype in database
using Hibernate with Session Bean
Validation/DB query question
Extracting a column value from a row
parsing a simple string