ResultSet findColumn - expensive to execute?

T

timasmith

Hi,

I have a method which maps resultsets to objects - one row only in this
method.

I have several different SQL, with different columns selected - each
using the same method.

Is the following expensive to execute for every column for every row?

try {
rset.findColumn(columnName);
} catch (SQLException se) {

}

I use it to check that the column is in the resultset - prior to
executing the copy of the value to the model. Is this too expensive to
run - if I had 100 rows returned with 10 columns, it would run a 1000
times. But perhaps this is negligible compared to other overhead?

Is there a better way to execute the various getString, getInt etc. for
only columns in the resultset?

thanks

Tim
 
M

Marc E

i can't answer this, but you might download the source for jakarta's DBUtils
package, which does resultset-->object mapping, and see how they do it. I've
found the resultset-to-bean stuff to be reasonably speedy, at least for
modestly sized resultsets.
 
R

Roedy Green

Is the following expensive to execute for every column for every row?

try {
rset.findColumn(columnName);
} catch (SQLException se) {

It may well depend on the JDBC driver. You had best test your
particular case.
 
T

Thomas Hawtin

Is the following expensive to execute for every column for every row?

try {
rset.findColumn(columnName);
} catch (SQLException se) {

}

If you are going to only use the column index, you might as well use the
getXxx(String) variant (assumes you are not using wasNull).

I wouldn't bother catching SQLException at every method invocation.

It would take a very broken driver for the small table look up to be
anything other than tiny. Relative to executing SQL over a network
connection, it is absolutely negligible.

You might want to optimise it, just so that there is one less thing to
worry about. This is the sort of nonsense code which is suited to
automation.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top