File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes passing parameters using Prepared Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "passing parameters using Prepared Statement" Watch "passing parameters using Prepared Statement" New topic
Author

passing parameters using Prepared Statement

C Vivek
Ranch Hand

Joined: Oct 03, 2004
Posts: 115


The above code does not return anything in the ResultSet whereas if I hardcode value instead of the "?" in the query string, it executes properly.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38350
    
  23
That "like" would return an item name with a ? in. Is that what you really want?
Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

should'nt the code be something like this? :


When the compiler's not happy, ain't nobody happy.
C Vivek
Ranch Hand

Joined: Oct 03, 2004
Posts: 115
Thanks Janardhan,
That worked, however is there something in the code that makes it retrieve only a single record?

When I run the query in the Backend it does return the exact no of records (which can be more than 1) however in the prepared statement in the code above it is retrieving only one.

Would be glad if you can help me here.


Regards,
Vivek

Paul Yule
Ranch Hand

Joined: May 12, 2008
Posts: 229
I don't think so. How are you iterating the results?
Janardan Kelkar
Ranch Hand

Joined: May 05, 2008
Posts: 72

Replace the 'if' on line 14 in your code with a 'while'. that should do it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: passing parameters using Prepared Statement