How do you convert a ResultSet object to an ArrayList of a different type.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Al_Colucci
Posted On:   Friday, March 15, 2002 02:25 PM

How do you convert a ResultSet object to an ArrayList of a different type.


Please use html tags to format code blocks.

Just loop through . . .

Posted By:   Roger_Hand  
Posted On:   Friday, March 15, 2002 10:32 PM

Not sure what you mean. I'm guessing that you have one field you want to pull from the ResultSet that you want to put into an ArrayList?


If so, try this:


String SQL = "SELECT FieldName FROM YourTable";
java.util.ArrayList AList = new ArrayList();
try {
Statement sqlStatement = Conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ResultSet RS = sqlStatement.executeQuery(SQL);
while (RS != null && RS.next()) {
AList.add(RS.getString("FieldName"));
} // next row
} catch (SQLException e) {System.out.println(this + " SQLException with SQL =
" + SQL + "
" + e.getMessage());}

About | Sitemap | Contact