List Columns in a ResultSet

Posted by in Software, Tutorial

In order to list all columns in a JDBC ResultSet (e.g. for debug purposes), you need to iterate through its metadata:

Note: Column numbers start from 1, not 0 (hence the md.getColumnName(i + 1) above).

I usually wrap this in a if(logger.isTraceEnabled()) so it doesn’t get triggered all the time.


A little experiment: If you find this post and ad below useful, please check the ad out :-)