Hi Noel,


On Monday, 9 February 2015 19:14:32 UTC+6:30, Noel Grandin wrote:
>
> Hi 
>
>
> On 2015-02-09 02:21 PM, Steve McLeod wrote: 
> >          final ResultSet resultSet = conn.prepareStatement("SELECT * 
> FROM foobar").executeQuery(); 
> >          int rowCount = 0; 
> >          while (resultSet.next()) { 
> >              rowCount++; 
> >              final int columnCount = 
> resultSet.getMetaData().getColumnCount(); 
> >              for (int column = 1; column <= columnCount; column++) { 
> >                  final String columnName = 
> resultSet.getMetaData().getColumnName(column); 
> >                  final int anInt = resultSet.getInt(columnName); 
> >              } 
> >          } 
>
> You should rather be retrieving the column names once, and then retrieving 
> the result-set columns using the getXXX(int 
> columnIndex) methods. 
>
>
I agree - that would help my (contrived) case. My actual code doesn't use 
meta-data to get column names, but sources the column names from elsewhere. 
I can certainly fix the problems on my end.

But I think there is an opportunity to add a tiny performance improvement 
in general here. Iterating over a result set, using getXXX(String 
columnName) is very common use of JDBC. We're not talking 10% speed 
improvement, but perhaps 1% in some cases? I don't know for sure - I'm just 
guessing based on the profiling.
 

> The only other thing I can think of that might speed it up would be to 
> modify the current caching code to use a TreeMap 
> with a custom comparator and then set the comparator to 
> java.lang.String.CASE_INSENSITIVE_ORDER. 
> That would avoid the extra String object creation, at the very least. 
>

Sounds good. Will java.lang.String.CASE_INSENSITIVE_ORDER be satisfactory? 
The Javadocs state: "Note that this Comparator does not take locale into 
account, and will result in an unsatisfactory ordering for certain 
locales." I think that means it is acceptable for H2's case, but I'm not 
certain.


Regards,

Steve

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To post to this group, send email to h2-database@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to