当前位置:   article > 正文

oracle exception查询,MyBatis查询Oracle数据表抛MyBatisSystemException异常

mybatissystemexception persistenceexception nullpointerexception

环境介绍

MyBatis版本3.*

数据库版本Oracle 11g

JDBC驱动ojdbc6-11g.jar

在使用MyBatis根据用户名查询User表用户信息时,抛 “MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: Error querying database.  Cause: java.lang.NullPointerException” 错误信息,但是不带参数去查询数据库又是真确的,纠结了半天,最终认为是jdbc驱动问题,于是替换一个jdbc驱动就解决了。

详细错误日志

### The error may involve com.hxstrive.persistence.mapper.CommonMapper.getUserInfo

### The error occurred while handling results

### SQL: SELECT u.ACCOUNT_ID, u.ACCOUNT_NAME, u.USER_NAME, u.USER_CODE, u.ORGANIZE_ID FROM USER u WHERE u.IS_DELETED!='1' AND u.ACCOUNT_NAME=?

### Cause: java.lang.NullPointerException, mergedContextConfiguration = [MergedContextConfiguration@4ae82894 testClass = CommonMapperTest, locations = '{classpath:applicationContext.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextCustomizers = set[[empty]], contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class annotated with @DirtiesContext [false] with mode [null], method annotated with @DirtiesContext [false] with mode [null].

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: java.lang.NullPointerException

### The error may exist in file [D:\test_persistence\target\classes\sql\orcle\CommonMapper.xml]

### The error may involve com.hxstrive.persistence.mapper.CommonMapper.getUserInfo

### The error occurred while handling results

### SQL: SELECT u.ACCOUNT_ID, u.ACCOUNT_NAME, u.USER_NAME, u.USER_CODE, u.ORGANIZE_ID FROM USER u WHERE u.IS_DELETED!='1' AND u.ACCOUNT_NAME=?

### Cause: java.lang.NullPointerException

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)

at com.sun.proxy.$Proxy24.selectOne(Unknown Source)

at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)

at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:83)

at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)

at com.sun.proxy.$Proxy25.getUserInfo(Unknown Source)

at com.hxstrive.persistence.mapper.CommonMapperTest.getUserInfo(CommonMapperTest.java:110)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:497)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)

at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)

at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

Caused by: org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: java.lang.NullPointerException

解决办法

将上面的ojdbc驱动替换成合适的jdbc驱动,我这里替换成ojdbc6-11.2.0.jar

点击学习 MyBatis 教程,了解更多的 MyBatis 知识!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/173815
推荐阅读
相关标签
  

闽ICP备14008679号