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)->execu teQuery->g etString.
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!
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
Thank you very much
ASKER
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!
Please comment on it again!
ASKER