Meaningless Drivel is fun!*
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: 38107
    
  22
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing parameters using Prepared Statement
 
Similar Threads
I am lost... Help me please
Getting EXception
how to improve my program code ?
jdbc in Unix
Geting an SQL Exception while passing the resultset to a bean