日期:2014-05-17  浏览次数:20808 次

mybatis在插入的时候,获取插入主键报错 T_T
这是配置
XML code

<insert id="insert" parameterType="com.imad.po.UserInfo" useGeneratedKeys="true" keyProperty="uId">
    insert into tbl_UserInfo(uUserName,uPassword)
    values(#{uUserName},#{uPassword})
</insert>




数据库中的表是
SQL code
create table tbl_UserInfo(
    uId int primary key auto_increment,
    uUserName varchar(255),
    uPassword varchar(255)
);


如果去掉
XML code
useGeneratedKeys="true" keyProperty="uId"

没有任何问题,将【uId】,换成了【uID】也不会报错

但是加上的话,会报错。。。差了半天没有找到原因
Java code
Exception in thread "AWT-EventQueue-0" org.springframework.jdbc.BadSqlGrammarException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: Column 'null' not found.
; bad SQL grammar []; nested exception is java.sql.SQLException: Column 'null' not found.
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:98)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:346)
    at $Proxy3.insert(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:231)
    at com.imad.dao.UserInfoDAO.insert(UserInfoDAO.java:71)
    at com.imad.service.UserInfoService.insert(UserInfoService.java:56)
    at com.imad.ui.ExRegister.doActionOnBtnNextClicked(ExRegister.java:159)
    at com.imad.ui.ExRegister.access$2(ExRegister.java:146)
    at com.imad.ui.ExRegister$3.mouseClicked(ExRegister.java:110)
    at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent