要更新MySQL的jar包版本_mysql jar 包版本更新问题

最近将以前写的代码重构了一遍,在重构的过程中一时兴起将mysql的jar包由5.0.4更新为5.1.16,启动项目后发现出现了一些异常情况。

首先是在插入数据的时候获得主键时抛出异常:org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [S1009]; error code [0]; Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().; nested exception is java.sql.SQLException: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().

解决方法:

将PreparedStatement ps = con.prepareStatement(sql);修改为

PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

KeyHolder keyHolder = new GeneratedKeyHolder();

jdbcTemplate.update(new PreparedStatementCreator() {

@Override

public PreparedStatement createPreparedStatement(Connection con) throws SQLException {

PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

return ps;

}

}, keyHolder);

其次就是在同一张表进行连接查询时老是抛出找不到列的异常:

Nested in org.springframework.jdbc.InvalidResultSetAccessException: 列名无效; nested exception is java.sql.SQLException: 列名无效:java.sql.SQLException: 列名无效

该查询的sql语句为:select t1.a, t1.b, t1.c, t1.d,  t1.e,  t2.a x, t2.b y, t2.c z, from table_a t1 left join table_a t2 on t1.c = t2.a where t1.a=?

SqlRowSet srs = jdbcTemplate.queryForRowSet(sql);

if(srs.next()){

...

srs.getInt("x");

...

}

在执行到srs.getInt("x")代码时就抛出上述异常了,事实上是所有的t2列都出现列名无效的错误,该问题还没有解决掉,但将jar包换回之前的版本5.0.4就一切正常了。

这次汲取了一个经验:不到万不得已的情况下不要轻易的将项目的环境升级,如果实在要升级也要将项目中与升级了的相关功能模块重新测试一编。

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2011-06-24 21:18

浏览 5951

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值