How can i retrieve a jdbc resultset as an arraylist




















Instead of iterating millions of times through the ResultSet and copying everything one-by-one to an ArrayList, is there some way to simply retrieve everything as an ArrayList? I understand that ResultSet is supposed to be iterated because the underlying implementation may be caching stuff, but in my situation I just need all the IDs straight away.

Clarification: the reason I want to do this is performance. Profiling shows me that doing ResultSet. I figure that the database I'm using H2, which is written in Java probably has the array or list somewhere in memory, so I'm looking for a way to have it copied to me directly instead of through the ResultSet iterating interface.

Experiment with , , ,.. Mark Mark This won't outperform JDBC itself? Agreed, it looks more convenient, but certainly, it isn't faster? Have a look at their site for some of the advantages of using DbUtils. I understand, yet the OP seems to have changed the question after you had answered. It's hard to answer without knowing what the OP is doing with the IDs. I would not look to optimize the iteration but try to figure out a way to accomplish the same task so that it doesn't require populating a local data structure with millions of IDs.

Put the code in a method. It's very simple to call methods Tom Hawtin - tackline Tom Hawtin - tackline k 30 30 gold badges silver badges bronze badges.

I believe he just wants to dump it. The last paragraph of the question was not in the original, btw. If your problem is poor performance, tune the statement before executing it with java. Antonio Antonio 2, 1 1 gold badge 15 15 silver badges 8 8 bronze badges. If you know the fetch size you're going to use, you could also declare in the ArrayList constructor the initial size of its internal array as the same amount.

Daddy From what I understood, the question's author was adding all returned IDs to a single list. This means that your suggestion really does not help unless you create an array with the full size of the result set, not only the fetchsize. Deckard, This question is still has no accepted answer, Did you solve this problem? Unfortunately, JDBC simply does not expose such a construct so the only possible way to do this would be if some Java-implemented database would explicitly expose it.

Sign up or log in Sign up using Google. Sign up using Facebook. For each datatype there is a method to get the value from the ResultSet.

Look in the Java API for the different kinds of methods. Python Javascript Linux Cheat sheet Contact. I will help u out :! Tags: Java Jdbc Resultset. Why isn't there a openjdkjdk package on debian anymore?



0コメント

  • 1000 / 1000