.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '0', will no

iBatis resultMap报错 nullValue完美解决

url: http://blog.csdn.net/liguohuaty/article/details/4038437

 

错误信息:

SQLErrorCodesFactory - Database product name cached for DataSource [org.apache.commons.dbcp.BasicDataSource@19c5048]: name is 'MySQL'
SQLErrorCodesFactory - SQL error codes for 'MySQL' found
SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with Error code '0', will now try the fallback translator
DataSourceUtils - Returning JDBC Connection to DataSource
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];  
--- The error occurred in net/jbbs/dao/ibatis/map/user.xml.
--- The error occurred while applying a result map.
--- Check the user.userResult.
--- The error happened while setting a property on the result object.
--- Cause: net.sf.cglib.beans.BulkBeanException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in net/jbbs/dao/ibatis/map/user.xml.
--- The error occurred while applying a result map.
--- Check the user.userResult.
--- The error happened while setting a property on the result object.
--- Cause: net.sf.cglib.beans.BulkBeanException
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in net/jbbs/dao/ibatis/map/user.xml.
--- The error occurred while applying a result map.
--- Check the user.userResult.
--- The error happened while setting a property on the result object.
--- Cause: net.sf.cglib.beans.BulkBeanException
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541)
at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:243)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:193)
at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:241)
at net.jbbs.dao.ibatis.UserDAOImpl.findByEmail(UserDAOImpl.java:54)
at net.jbbs.test.UserTest.findByEmail(UserTest.java:42)
at net.jbbs.test.UserTest.main(UserTest.java:34)
Caused by: net.sf.cglib.beans.BulkBeanException
at net.jbbs.domain.User$$BulkBeanByCGLIB$$88b6b34d.setPropertyValues(<generated>)
at com.ibatis.sqlmap.engine.accessplan.EnhancedPropertyAccessPlan.setProperties(EnhancedPropertyAccessPlan.java:33)
at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)
at com.ibatis.sqlmap.engine.mapping.result.BasicResultMap.setResultObjectValues(BasicResultMap.java:373)
at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:382)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:301)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:190)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteQuery(GeneralStatement.java:205)
at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:173)
... 10 more

这个错误指出resultMap里有问题。说错误发生在设置某一个属性的时候,但是没有具体说明是一个怎么样的错误<NULL错误>。由于对于iBatis了解还不是很深,所以一时不知如何事好。只有在resultMap里面作文章,把里面的<result>注释掉一些,哈哈,程序居然正常跑起来了。看来我快要找到错误了,接着继续排除其它的<result>,终于让我找到出错的一行<result>了:  

    <result column="ORDER_NUM" property="orderNum" jdbcType="long" />

  接下来得弄清楚是一个什么样的错误,怎么去修复它。查找数据库表,发现"orderNum"这一列是nullable,并且没有为它设置默认值。所以表里面orderNum这一列有许多都为NULL。我大概明白了,肯定是iBatis试图把从数据库读出来的NULL 值写入对象属性的时候出现异常。

        采取的补救措施就是:
          <result column="ORDER_NUM" property="orderNum" jdbcType="long"  nullValue="0"/>
对从数据库读出来的NULL值采用一个相应可转换为orderNum类型的值来替换

附:
 <resultMap id="pageStaticItemMap" class="PageStaticItem">
  <result column="ITEMID" property="itemId" jdbcType="long"/>
  <result column="ITEMNAME" property="itemName" jdbcType="String"/>
  <result column="SERVERID" property="serverId" jdbcType="long"/>
  <result column="SOURCE" property="source" jdbcType="String"/>  
  <result column="TARGET_PATH" property="targetPath" jdbcType="String"/>
  <result column="TARGET_FILE" property="targetFile" jdbcType="String"/>
  <result column="LOCAL_PATH" property="localPath" jdbcType="String"/>
  <result column="FTP_PATH" property="ftpPath" jdbcType="String"/>
  <result column="ITEMTYPE" property="itemType" jdbcType="String"/>  
  <result column="EXT1" property="ext1" jdbcType="String"/>
  <result column="EXT2" property="ext2" jdbcType="String"/>
  <result column="EXT3" property="ext3" jdbcType="String"/>
  <result column="EXT4" property="ext4" jdbcType="String"/>
  <result column="ORDER_NUM" property="orderNum" jdbcType="long" /><!--这一行加一个nullValue="0"就OK了-->
  <result column="ITEM_TYPE" property="item_Type" jdbcType="String"/>
  <result column="SERVER_PROPERTIES" property="serverProperties" jdbcType="String"/>
  <result column="GET_SQL" property="getSql" jdbcType="String"/> 
 </resultMap>

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您好,对于 DruiDataSource 的创建连接时发生的 SQLException 错误,通常有以下几种可能的原因和解决方法: 1. 数据库连接配置错误:请检查数据库连接配置是否正确,包括数据库地址、端口号、用户名、密码等。确保这些配置与您的数据库实例的设置相匹配。 2. 数据库服务不可用:如果数据库服务不可用或者连接超时,也会导致创建连接时出现 SQLException。请确保数据库服务正在运行,并且网络连接正常。 3. 数据库连接池配置问题:如果您在使用连接池技术,比如 Druid 提供的连接池,那么请检查连接池的配置是否正确。例如,连接池的最大连接数、最小连接数、连接超时时间等配置参数是否合理。 4. 数据库访问权限问题:有时候数据库用户没有足够的权限来创建连接,或者连接数超过了数据库的限制。请检查数据库用户的权限设置,并确保没有超出数据库允许的最大连接数。 5. 数据库驱动版本不兼容:如果您使用的数据库驱动与您的数据库版本不兼容,也可能导致创建连接时出现 SQLException。请使用与您的数据库版本相匹配的驱动版本。 根据具体的错误信息和排查过程,您可以进一步确定导致 SQLException 的原因,并采取相应的解决措施。如果问题仍然存在,请提供更多的详细信息,以便我们能够更好地帮助您解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值