Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resultset.next() taking more time

 
murugesan govindan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
sivaraju kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic