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 Performance question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Performance question" Watch "Performance question" New topic
Author

Performance question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!
Which is more efficient (when reading select statement's resultset):
ResultSet.getString(int columnNumber)
or

ResultSet.getString(String columnName)?
It would seem that the first would have better performance but what do you think?
Greetings,
Jukka
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1506
You are correct, the fist one should be faster. It can be ian issue though if the table structure changes. i.e if the ordering of the columns changes.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by Jukka Palom�ki:
Hi!
Which is more efficient (when reading select statement's resultset):
ResultSet.getString(int columnNumber)
or

ResultSet.getString(String columnName)?
It would seem that the first would have better performance but what do you think?
Greetings,
Jukka

The performance gain in the most extreme cases could probably not be detected. But for the readability and ease of maintenance factor, I highly recommend using ResultSet.getString(String columnName). Instead of trying to tweek microseconds off your program execution, if your concerned about performance, it is better to look at using the jdbc interface correctly ( like tips from this link ). If you still notice poor performance, use a profiler to see where the real bottlenecks are.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Performance question
 
Similar Threads
compiled or not compiled
Checking If Condition
retrieveing fields from table
java.sql.SQLExceptiion: Column Index out of range (0>1)
Exception in Microsoft ODBC driver