• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to save value from ResultSet as a single value in database  RSS feed

 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Sheriff
Posts: 37395
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much, it works perfectly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!