Link to home
Start Free TrialLog in
Avatar of tomytsui
tomytsui

asked on

Question in JDBC

I'm using JDBC to execute "select customer_name from customer where customer_num = ? " in database by calling prepareStatement->setInt(1,n)->executeQuery->getString.
But the result is correct for the first attempt only. When I using a for-loop to change variable n and all of the results will become the same as the first record I retrieved! Please give me some advice on how to use prepareStatement correctly! Thank you for your help!
ASKER CERTIFIED SOLUTION
Avatar of sunot
sunot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tomytsui
tomytsui

ASKER

Is that means I should clearParameter() before setInt again?
The clearParameter is just there to ensure that all the older parameter values are removed before specifying a new one. This is so that you wouldn't have a concat value of the parameter in use.
Thank you very much
I have tried your method in prepare query statement, it is not working as before! But I try to use prepareStatement to perform insert or update statements, they work well! So I think there is something wrong in ResultSet returned by executeQuery(), it always store the result of the first attempt!

Please comment on it again!