db2jcc4.jar无法获取通过别名查询结果的值?原因何在?!!!

先上结论:最简单的办法就是换成db2jcc.jar驱动即可!

若不想换呢?那继续看啊。。。

db2jcc.jar用于jdbc3.0,db2jcc4.jar用于jdbc4.0,而IBM对于jdbc4.0的规范进行了修改!!!

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DB2的 jdbc驱动升级到V4后使用 ResultSetMetaData.getColumnName不能获取列的别名的问题

最近把db2的jdbc驱动升级到了 Version4.0, 遇到下面的问题:
以前的代码中通过ResultSetMetaData.getColumnName来获取查询语句列的别名,更新后获取的是列的名字。
经查是因为IBM根据jdbc的规范进行了相关修改, 官方信息和解决方案如下:
 

ResultSetMetaData returns different values for the IBM Data Server Driver for JDBC and SQLJ Version 4.0

For the IBM® Data Server Driver for JDBC and SQLJ Version 4.0, the values that are returned for ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel are changed to conform to the JDBC 4.0 standard. Those values differ from the values that are returned for the IBM Data Server Driver for JDBC and SQLJ Version 3.50 and earlier JDBC drivers.

Details

The results vary, depending on the following factors:
  • Which data source type and version you are using. DB2® for z/OS® and OS/390 Version 7 and DB2 for i5/OS® V5R2 are unaffected by this change. Only later versions of these database products and all versions of DB2 Database for Linux, UNIX, and Windows and IBM Informix® Dynamic Server are affected.
  • Whether a column in the SELECT list of a query has an AS clause. For JDBC drivers before the IBM Data Server Driver for JDBC and SQLJ Version 4.0, if a column in the SELECT list of a query contains an AS clause, ResultSetMetaData.getColumnName returns the argument of the AS clause. Under the IBM Data Server Driver for JDBC and SQLJ Version 4.0, ResultSetMetaData.getColumnName returns the table column name.
  • Whether a column in the SELECT list of a query has a label from a LABEL statement but no AS clause. DB2 for z/OS and DB2 for System i support the LABEL statement, which assigns a label to a column. For JDBC drivers before the IBM Data Server Driver for JDBC and SQLJ Version 4.0, if a column in the SELECT list of a query has a label, ResultSetMetaData.getColumnName returns the table column name, and ResultSetMetaData.getColumnLabel returns the column label from the LABEL statement. Under the IBM Data Server Driver for JDBC and SQLJ Version 4.0, ResultSetMetaData.getColumnName and ResultSetMetaData.getColumnLabel return the table column name. The column label from the LABEL statement is not used.
  • Whether a column in the SELECT list has a label from a LABEL statement and an AS clause. For JDBC drivers before the IBM Data Server Driver for JDBC and SQLJ Version 4.0, if a column in the SELECT list of a query has a label and an AS clause, ResultSetMetaData.getColumnName returns the argument of the AS clause, and ResultSetMetaData.getColumnLabel returns the column label from the LABEL statement. Under the IBM Data Server Driver for JDBC and SQLJ Version 4.0, ResultSetMetaData.getColumnName returns the table column name, and ResultSetMetaData.getColumnLabel returns the argument of the AS clause. The column label from the LABEL statement is not used.

Resolution

If you cannot change your applications to conform to the new  ResultSetMetaData  behavior but you need other features of JDBC 4.0, set the useJDBC4ColumnNameAndLabelSemantics  Connection  or  DataSource  property to  DB2BaseDataSource.NO  (2) to keep the old behavior.
 
我使用的是tomcat的datasource, 所以在datasource配置中增加连接属性设置:connectionProperties =“useJDBC4ColumnNameAndLabelSemantics=2”
 
 
参考:
 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: DB2JCC4.jar是IBM DB2数据库的Java驱动程序。它是用于在Java应用程序中连接和操作DB2数据库的必备文件。DB2JCC4.jar包含了与DB2数据库的通信和数据操作所需的所有类和方法。它可以通过IBM官方网站或其他相关网站进行下载。 要下载DB2JCC4.jar文件,可以按照以下步骤进行操作: 1. 打开网络浏览器,访问IBM官方网站或其他可信赖的软件下载网站。 2. 在网站的搜索栏中输入“DB2JCC4.jar文件下载”。 3. 在搜索结果中找到适合你的操作系统和Java版本的DB2JCC4.jar文件。 4. 点击下载链接,开始下载DB2JCC4.jar文件。 5. 下载完毕后,将DB2JCC4.jar文件保存到你的计算机的合适的目录中,通常是你的Java项目所在的目录或lib目录。 6. 在你的Java项目中,配置构建路径或类路径,以便能够找到并使用DB2JCC4.jar文件。这样,你的Java应用程序就可以连接和操作DB2数据库了。 请注意,下载DB2JCC4.jar文件之前,你需要确保你已经获得了合法的许可证来使用DB2数据库。此外,为了避免安全风险,建议只从可信赖的来源下载DB2JCC4.jar文件。 通过以上步骤,你就可以成功下载并使用DB2JCC4.jar文件来连接和操作DB2数据库了。 ### 回答2: 要下载db2jcc4.jar文件,需要按照以下步骤进行操作: 1. 打开IBM官方网站。在浏览器中输入“IBM官方网站”并打开。 2. 寻找DB2数据库驱动程序下载页面。在IBM官方网站的搜索栏中输入“DB2数据库驱动程序下载”并搜索。 3. 选择合适的下载链接。根据你使用的DB2数据库版本和操作系统,选择相应的下载链接。确保选择的链接是符合你的系统要求的。 4. 点击下载链接。一旦找到合适的链接,点击下载按钮开始下载db2jcc4.jar文件。 5. 确认下载完成。等待下载完成后,可以在浏览器的下载列表或指定的下载目录中找到db2jcc4.jar文件。 6. 将db2jcc4.jar文件添加到项目中。如果你需要在Java项目中使用db2jcc4.jar文件,将其添加到相关的库文件夹中。可以通过右键单击项目,选择“Build Path”或类似选项,然后选择“Add JARs”或类似选项,导航到下载的db2jcc4.jar文件并选择添加。 7. 测试连接。在你的Java项目中,使用db2jcc4.jar文件建立数据库连接,并编写一些测试代码来验证连接是否成功。 以上就是关于db2jcc4.jar文件下载的简要说明。希望对你有所帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值