File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Converting to prepared statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Converting to prepared statement" Watch "Converting to prepared statement" New topic

Converting to prepared statement

Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
I am trying to convert a simple sql to prepared stmt..I am expecting the following functions to behave same..but I guess they dont.
Can someone guide me with the correct implementation please..

Thank you

SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

SELECT * from inventory_table it WHERE it.itemId = id.getItemId()

This is not valid SQL.
What do the functions do differently?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Himalay Majumdar
Ranch Hand

Joined: Sep 28, 2008
Posts: 324
id.getItemId() will return a String, representing number

Also..its not..stmt.setString(1, id.getReturnId()) on line 17..

It is stmt.setString(1, id.getItemId())

I was able to resolve the issue using our framework functionality.

But still am curious to know..if it is possible to update the query using the Statement methods..such as setString(1, "1111");

so when I do.. return query.toString(); I can return the query with the updated values in place of question mark

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
No, it don't.

Execute it and compare the results.
I agree. Here's the link:
subject: Converting to prepared statement
It's not a secret anymore!