Can anyone tell me why this error would occur?
Only the obvious reason given by the exception
B@2ca6d51eException in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
We have no idea which is 'line 76' or what array index values you are using.
You need to conduct your own basic troubleshooting. Review the array index values being used by either using a GUI debugger or by printing out the values.
System.arraycopy(rs.getMetaData().getColumnLabel(c).getBytes(), 0, buf, 0, rs.getMetaData().getColumnLabel(c).length());
We have no idea what the size of 'buf' is or what 'length' value is being used. Look at the values being used and the problem should be obvious.
On an unrelated observation:
Your code may work fine if the column name is less than the max char size and column type is varchar.
What if the column name is equal to max char size? Can it handle it?
What if the column name is greater than max char size? Can it handle it?
What if the column type is something other than varchar such as char, int, date? Can it handle it?