This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes PreparedStatement Change 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 » Databases » JDBC
Bookmark "PreparedStatement Change" Watch "PreparedStatement Change" New topic
Author

PreparedStatement Change

vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
I am trying to convert this dyanamic query into a preparedStatement to fetch data from a table in an efficent way.The query has 4 attributes which are required to be displayed according to the user input and even if the user enters only one input it should return all the other attributes.





Some one please help me with this,I am not able to make the query in the if statement as prepared statement.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

vijay, please CarefullyChooseOneForum. I've removed the identical threads you started in Java in General and Performance.


luck, db
There are no new questions, but there may be new answers.
rav pad
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Vijay,

You mean to say con.prepareStatement(YOUR QUERY) doesnt work?
vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
I am sorry for multiple post Darryl.

Hello Rav,the first query using select is appended at every if condition used,So i just need to make those query=query+..... statements as prepared statements.
vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
People,do you need more clarity on this?
rav pad
Greenhorn

Joined: Jun 07, 2011
Posts: 3
Vijay,
I understood your requirement. This is query is used for a search page where the results are displayed based on the conditions selected.
1) Do you want to pass on the paramters to the statement during run time like we do for prepared statements?
2) If yes for above question then how do you intend to construct the query?
3) Why do you want to use preparedstatements?

Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

Vijay,

I don't understand. What your problem with this. from your code, i find that, you are not binding the values to the query, you append it to query. Then you can simply use Statement instead of prepared statement


Ashwin Sridhar
SCJP | SCWCD | OCA
 
Consider Paul's rocket mass heater.
 
subject: PreparedStatement Change
 
Similar Threads
Dynamic SQL Query Doubt
inserting an image in to database
Very New To Java Question Help Please!
Urgent: Setting values for the bind parameters of a RowSet query
Need your expert opinion!