java - JDBC ResultSet method next() is taking 30 seconds to fetch 12000 rows -


i'm fetching data using callablestatement stored proc, resultset has 12000 rows , taking 30 seconds process. i'd tried setting fetch size (rs.setfetchsize(500) still, taking same time fetch whole data (30 sec).

callablestatement = conn.preparecall(myproc); callablestatement.setstring("myparam", xyz); callablestatement.registeroutputparameter("revtal", oracletypes.cursor); callablestatement .setfetchsize(1000); // have tried different values rs = (resultset) callablestatement.getobject("revtal");  while(rs.next()) {`     mymethodtosetresultintolist(); } 

is there possible way other fetch size optimize it?

i have tried this:

while(rs.next()) {`         logger(); // nothing     } 

it processed 12000 rows in approx 3 seconds, time getting consumed in fetching data resultset.

also, confirmed setfetchsize() working without setting fetch size showing "fetchedrowcount" 10 , setfetchsize() x, showing "fetchrowcount" x on debug mode.

actual while loop this:

while(rs.next()) {     myclass mc = new myclass();     mc.seta(rs.getstring("parametera");     mc.setb(string.valueof(rs.getlong("parameterb");     //4 more string parameters same     mc.setg(mymethodtoconvertdate(rs.getdate("date");     mylist.add(mc); } 

so taking approx 25 seconds retrieve data resultset , adding mylist. there must solution this.

thanks in advance

a little clarification regard fetchsize. in code there callablestatement out parameter , cursor. setfetchsize has no impact on callablestatement returns 1 set of results, out parameters. in case there 1 out parameter, cursor. getcursor call returns resultset.

best can recall there nothing in jdbc spec says fetchsize of resultset created cursor should be. (my memory fallible.) oracle database jdbc drivers set fetchsize of cursor resultset same statement created it.

so in case setting fetchsize of callablestatement nothing result retrieved callablestatement set fetchsize of resultset created cursor. comment usagi miyamoto correct @ least respect callablestatement comment seeing expected behavior setting fetchsize correct.

iterating on cursor resultset fetches data database. state takes 3 seconds. when process rows takes 20 seconds. setting fetchsize not speed (or slow) down row processing, database fetch. within limits setting fetchsize not speed things up. (those limits fetchsize has big enough minimize number of database round trips , small enough keep memory footprint reasonable. 100 number. larger better.)

but fetchsize of 1000 code fetching rows in 3 seconds. 100 might let app run faster overall uses less memory, secondary question. real question why take ~17 seconds process 12,000 rows? not fetch them, process them. function of number , types of columns , how processed. have not provided information in regard.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -