首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql jar 包版本更新有关问题

2012-07-27 
mysql jar 包版本更新问题?最近将以前写的代码重构了一遍,在重构的过程中一时兴起将mysql的jar包由5.0.4更

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);

SqlRowSet srs = jdbcTemplate.queryForRowSet(sql);if(srs.next()){    ...    srs.getInt("x");    ...}

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

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

热点排行