Tuesday, January 12, 2010

Re: Can I Cast a ResultSet to an ArrayList/DTO?

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.

On Jan 12, 9:14 am, Russ <r...@epcinternet.com> wrote:
> 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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate