项目中一直使用了mysql-connector-java-5.0.7-bin.jar驱动包,
近来更新成:mysql-connector-java-5.1.7-bin.jar,
在一个关键地方,应用总是报异常,左思右想,我换过包,下面做一些简单测试:
1、工程使用mysql-connector-java-5.0.7-bin.jar
mysql> select version();
+-----------------+
| version() |
+-----------------+
| 5.1.16-beta-log |
+-----------------+
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.1.48 |
+-----------+
调用方法:
getXXMap()
调用语句:
<select id="getXXMap" resultClass="java.util.HashMap">
select concat(countryId,gender,medalType) as conKey,countryId,gender,medalType,medalCount from tableName
</select>
select concat(countryId,gender,medalType) as conKey,countryId,gender,medalType,medalCount from tableName
返回结果
{CHNW3={medalCount=2, countryId=CHN, conKey=CHNW3, gender=W, medalType=3}, NGRM2={medalCount=1, countryId=NGR, conKey=NGRM2, gender=M, medalType=2}, FRAM2={medalCount=1, countryId=FRA, conKey=FRAM2, gender=M, medalType=2}, UZBM3={medalCount=2, countryId=UZB, conKey=UZBM3, gender=M, medalType=3}}
conkey类型:class java.lang.String
两台数据库服务器测试通过,获取数据类型正常。
2、工程使用mysql-connector-java-5.1.7-bin.jar
{{[B@1555185={medalCount=2, countryId=RUS, conKey=[B@1555185, gender=W, medalType=1}, [B@1f51e5c={medalCount=2, countryId=BRA, conKey=[B@1f51e5c, gender=M, medalType=3}, [B@1612190={medalCount=1, countryId=FRA, conKey=[B@1612190, gender=M, medalType=3}, [B@df8b14={medalCount=1, countryId=CUB, conKey=[B@df8b14, gender=M, medalType=2}, [B@834cfb={medalCount=3, countryId=CHN, conKey=[B@834cfb, gender=W, medalType=1}, [B@5585dc={medalCount=1, countryId=GER}
两台数据库服务器测试通过,但获取数据类型无法识别。
conKey类型:class [B
后记:
后来使用jdbcTemplate查询
select concat(countryId,gender,medalType) as conKey,countryId,gender,medalType,medalCount from tableName
返回结果是:
{conKey=[B@c713d2, countryId=ARG, gender=M, medalType=1, medalCount=1}
类型:class [B
可见,依然还是驱动包问题,换成mysql-connector-java-5.0.7-bin.jar即可。
上一步所做的,引发下一步的错误,那么可以怀疑上一步是有问题;如果N久后才发现这个错误,那么这个错误还不一定好找出来,在开发过程中,每一步的测试,还是需要做到位!
本文转自jooben 51CTO博客,原文链接:http://blog.51cto.com/jooben/382632