Can I Cast a ResultSet to an ArrayList/DTO?

101 views
Skip to first unread message

Russ

unread,
Jan 12, 2010, 9:14:50 AM1/12/10
to Google Web Toolkit
Is there any way to cast a JDBC ReultSet to an ArrayList of Strings
(or another type of DTO) with a single assignment statement?

Otherwise I end up iterating through the ResultSet twice - once on the
server to assign its values to an ArrayList of DTOs - and once after
its returned to the client in order to display the results. I'd rather
just assign (cast) the resultSet to the ArrayList and return it. For
example:

Rather than do this on the server:

resultSet = statement.executeQuery("SELECT first_name from
Employees");
while (resultSet.next()) {
arrayList.add(resultSet.getString("first_name")); //Loops through
over a hundred records
}
return arrayList;


It would be nice to simply do this:

resultSet = statement.executeQuery("SELECT first_name from
Employees");
arrayList = (ArrayList<Names>) resultSet; //Assign the entire
resultSet to the ArrayList
return arrayList;

Is this (or something similar) possible?

Thanks in advance,
-Russ

Lothar Kimmeringer

unread,
Jan 12, 2010, 9:39:56 AM1/12/10
to google-we...@googlegroups.com
Russ schrieb:

> Is there any way to cast a JDBC ReultSet to an ArrayList of Strings
[...]

> Is this (or something similar) possible?

No


Regards, Lothar

Sean

unread,
Jan 12, 2010, 9:59:32 AM1/12/10
to Google Web Toolkit
No, there isn't a way to do that. In the great scheme of things,
cycling through hundreds of items twice, isn't that big of a time
sink. If it's taking too long from request to display, think about
cutting up your query to only get say, 50 items. Display those and
only grab the next 50 when requested.
Reply all
Reply to author
Forward
0 new messages