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
Marc E - 11 Dec 2005 20:29 GMT
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.
> Hi,
>
[quoted text clipped - 23 lines]
>
> Tim
Roedy Green - 11 Dec 2005 20:34 GMT
>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.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Thomas Hawtin - 11 Dec 2005 21:17 GMT
> Is the following expensive to execute for every column for every row?
>
[quoted text clipped - 3 lines]
>
> }
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

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/