aspose file tools
The moose likes JDBC and the fly likes How to save value from ResultSet as a single value in database Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to save value from ResultSet as a single value in database " Watch "How to save value from ResultSet as a single value in database " New topic
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
    
  66

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to save value from ResultSet as a single value in database
 
Similar Threads
Unsure how to create and name dynamic Textfield
HTTP Status 405 - HTTP method GET is not supported by this URL
Problem with update data to database
getting only modified data for logging from component list
Column count doesn't match value count at row 1