File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Resultset.next() taking more time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Resultset.next() taking more time" Watch "Resultset.next() taking more time" New topic
Author

Resultset.next() taking more time

murugesan govindan
Greenhorn

Joined: Jan 02, 2008
Posts: 2
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

Joined: Aug 13, 2004
Posts: 1081

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


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
murugesan govindan
Greenhorn

Joined: Jan 02, 2008
Posts: 2
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

Joined: Jul 16, 2009
Posts: 1
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resultset.next() taking more time