简体   繁体   中英

DB2 and ResultSetMetaData - Unable to get column name

I am developping an application on WAS 8.0.0.5 that iteracts with a DB2 database.

I am getting the column name using java.sql.ResultSetMetaData call getColumnName() class. On my development WAS everything works great.

ResultSetMetaData rsmd = rs.getMetaData();
String columnName = rsmd.getColumnName(i + 1);

When I try and install on a WAS 8.0.0.6 instead of getting the column name, I get the column index!!!

The driver set for the connection string is com.ibm.db2.jcc.DB2Driver

As I side note, I've confirmed and WAS 8.0.0.5 uses DB2 driver 3.62 (works) and 8.0.0.6 uses 4.12 (doesn't work).

What is wrong?

The behaviour of getColumnName() and getColumnLabel() has changed in the IBM Data Server Driver for JDBC version 4. I believe it now conforms to the JDBC specification. You can use the connection property useJDBC4ColumnNameAndLabelSemantics to modify this behaviour, as explained here: http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_c0052593.html .

Thanks for the response.

Unfortunately it wasn't the solution. The behavior was that the column index was being returned, instead of the query's label or column name itself.

The problem was that the db2jcc.jar version, configured on the WAS JDBC resources, was too old (version 3.59) I replaced it for 4.12 and now it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM