| Author |
How to save value from ResultSet as a single value in database
|
vanan saravanan
Ranch Hand
Joined: Jun 02, 2006
Posts: 95
|
|
I'm using dynamic checkbox to retrive some values. It works fine but when i save to database it saves each record individually. I want to join all the records into one and save it as a single entry in the database. This is my code rst2 = stm1.executeQuery("select * from students"); String Childic = ""; for(int i = 0; rst2.next(); i++){ if(request.getParameter("ca1_"+i) !=null){ Childic = rst2.getString("Childic") ; String query2 = "INSERT into results(ca1) values ('"+Childic+"')"; stm2.executeUpdate(query2); } else{ } } Right now it saves as A - 1st record B - 2nd record C - 3nd record I want it to be A B C - 1st record Thank you for your help.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
Vanan, Since you only want one database entry, the update would go outside the loop. For example: One caveat - be sure there is enough space in the table for a potentially verylong record.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
vanan saravanan
Ranch Hand
Joined: Jun 02, 2006
Posts: 95
|
|
|
Thank you very much, it works perfectly.
|
 |
 |
|
|
subject: How to save value from ResultSet as a single value in database
|
|
|