ResultSet to Collection
1 posts in topic
Flat View  Flat View

Posted By:   Henry_Leung
Posted On:   Tuesday, September 2, 2003 08:50 PM

I would like to find a simply way to copy all data in a ResultSet into the server's memory. And this way should be generic enough to handle whatever the ResultSet contains.

I wonder if there is any open-source library/class package that provides method to fetch all data from a ResultSet object and automatically put everything into a Collection object?

Re: ResultSet to Collection

Posted By:   Aravind_Thangaraj  
Posted On:   Monday, December 1, 2003 09:39 PM

It is so simple friend...
Please go through the code fragment below...
List my_list = new List();
String qry = "SELECT * FROM "+your_table+" ;";
st.execute(qry); // st = Statement
rs = st.getResultSet(); // Result set
rs.beforeFirst(); // go to b4 the very first row
while(rs.next()) { // gives false, if no rows available
// here add all your code to get data from recordset and add it to the colection list.

// example...

String str1= rs.getString("id"); // an existing column in the table your_table. It returns the current data in the field "id".
String str2= rs.getString("passwd");
my_list.add(str1); // sorry guru, I am not remember the syntax. check it out.

Hope this may help to understand about your thirst...

Good day.
About | Sitemap | Contact