• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Resultset.next() taking more time

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

While analyzing the performance for my application, I have found that resultset.next() method taking more time to move cursor on first time. Resultset has only 10 records and when control reach at while(rs.next()) taking more time (14 sec) on first time (to reach first record) and after control get into the while loop its working fast.

is there any alternative method to iterate resultset other than next()?

Environment: Wbsphere Application server 6.1

code look like:

ResultSet rs = null;
CallableStatement cstmt = null;

cstmt = dbConnection.prepareCall(sql);
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
cstmt.executeQuery();

rs = (ResultSet)cstmt.getObject(1);

while(rs.next()){
//Only 10 times iterating as expected.
}

please advise me, why resultset.next() method taking more time to reach first record.

Regards
Murugesan
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It can also be your PL/SQL CURSOR , which might be causing this delay.

Did you run you procedure on sql console ? try to run procedure on SQL-plus and check if it is taking equal time as JDBC.

Thanks,
Shailesh
 
murugesan govindan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Procedure running in 1 second but after receing the resultset, if I call while(rs.next()) then its taking more time.

Regards
Murugesan
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Murguesh,
you Should have to excecute statement then you have to take the Cursor reuslts.
please find the code and let me know if still problem.

String query = useOracleQuery ? oracleQuery : genericQuery;
System.out.println("Query: " + query + "\n");
CallableStatement stmt = conn.prepareCall(query);

// register the type of the out param - an Oracle specific type
stmt.registerOutParameter(1, OracleTypes.CURSOR);

// set the in param
stmt.setFloat(2, price);

// execute and retrieve the result set
stmt.execute();
ResultSet rs = (ResultSet)stmt.getObject(1);

// print the results
while (rs.next()) {
System.out.println(rs.getString(1) + "\t" +
rs.getFloat(2) + "\t" +
rs.getDate(3).toString());
}

rs.close();
stmt.close();

Thanks
Sivakumar(IBM Friend)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic