MyBatis出现org.apache.ibatis.executor.ExecutorException异常

DEBUG [main] 
-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-

Opening JDBC Connection

DEBUG [main] 


-
 Created connection 
29011566

.

DEBUG [main] 


-
 Setting autocommit 
to
 
false
 
on

JDBC Connection [com.mysql.jdbc.JDBC4Connection@1baae6e]

DEBUG [main] 


-
 
==>
  Preparing: 
select
 
*
 from user where username like concat(?,

%’) 


DEBUG [main] 
-
 
==>
 Parameters: 张(
String

)

org.apache.ibatis.exceptions.PersistenceException: 

### 


Error
 querying database.  Cause: org.apache.ibatis.executor.result.ResultMapException: 
Error
 attempting 
to
 
get
 column 

username’ from result set.  Cause: java.sql.SQLException: Cannot convert value ‘张三’ from column 2 to TIMESTAMP.


### The 
error
 may exist in sqlmap
/

User.xml

### The 


error

may involve test.findUserByName3

### The 


error
 occurred 
while

handling results

### SQL: 


select
 
*
 from user where username like concat(?,

%’)


### Cause: org.apache.ibatis.executor.result.ResultMapException: 
Error
 attempting 
to
 
get
 column 

username’ from result set.  Cause: java.sql.SQLException: Cannot convert value ‘张三’ from column 2 to TIMESTAMP.


    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
30

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


149

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


140

)

at com.swjd.test.B.test2(B.java:


40

)

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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:


325

)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:


78

)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:


57

)

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.junit.runners.ParentRunner.run(ParentRunner.java:


363

)

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.executor.result.ResultMapException: 


Error
 attempting 
to
 
get
 column 

username’ from result set.  Cause: java.sql.SQLException: Cannot convert value ‘张三’ from column 2 to TIMESTAMP.


    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:
83

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createUsingConstructor(DefaultResultSetHandler.java:


671

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:


654

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:


618

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:


591

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:


397

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:


354

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:


328

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:


301

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:


194

)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:


65

)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:


79

)

at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:


63

)

at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:


324

)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:


156

)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:


109

)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:


83

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


147

)

     MyBatis出现org.apache.ibatis.executor.ExecutorException异常


24

more

Caused by: java.sql.SQLException: Cannot convert value 



张三’ from column 2 to TIMESTAMP.


    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:
1055

)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:


956

)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:


926

)

at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:


1328

)

at com.mysql.jdbc.ByteArrayRow.getTimestampFast(ByteArrayRow.java:


124

)

at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:


6669

)

at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:


5988

)

at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:


6026

)

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.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:


69

)

at com.sun.proxy.$Proxy6.getTimestamp(Unknown Source)

at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:


39

)

at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:


28

)

at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:


81

)

     MyBatis出现org.apache.ibatis.executor.ExecutorException异常


41

more

Caused by: java.lang.NumberFormatException: 张三

at com.mysql.jdbc.StringUtils.getInt(StringUtils.java:


756

)

at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:


1253

)

     MyBatis出现org.apache.ibatis.executor.ExecutorException异常


54

more

Process finished 


with
 
exit
 code 
-
1

上网找了一些答案也没有解决我的问题,

后来发现原来是User类的构造函数问题,找不到相关的构造函数;试着在User中加一个默认的构造函数,就解决了。。。

希望能帮到大家。

默认的构造函数在创建构造函数后,不会自动创建默认构造函数

DEBUG [main] 
-
 Logging initialized using 

class org.apache.ibatis.logging.slf4j.Slf4jImpl’ adapter.


DEBUG [main] 
-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-
 PooledDataSource forcefully closed
/

removed all connections.

DEBUG [main] 


-

Opening JDBC Connection

DEBUG [main] 


-
 Created connection 
27155935

.

DEBUG [main] 


-
 Setting autocommit 
to
 
false
 
on

JDBC Connection [com.mysql.jdbc.JDBC4Connection@19e5ddf]

DEBUG [main] 


-
 
==>
  Preparing: 
select
 
*
 from user where id
=

DEBUG [main] 


-
 
==>
 Parameters: 
27
(
Integer

)

org.apache.ibatis.exceptions.PersistenceException: 

### 


Error
 querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: 
Error
 instantiating class com.swjd.po.User 
with
 invalid types () 
or
 values (). Cause: java.lang.NoSuchMethodException: com.swjd.po.User.
<
init
>

()

### The 


error
 may exist in sqlmap
/

User.xml

### The 


error
 may involve test.findUserById
-

Inline

### The 


error
 occurred 
while

setting parameters

### SQL: 


select
 
*
 from user where id
=

?

### Cause: org.apache.ibatis.reflection.ReflectionException: 


Error
 instantiating class com.swjd.po.User 
with
 invalid types () 
or
 values (). Cause: java.lang.NoSuchMethodException: com.swjd.po.User.
<
init
>

()

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:


26

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


111

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


102

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:


66

)

at com.test.Test1.test1(Test1.java:


31

)

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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:


325

)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:


78

)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:


57

)

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.junit.runners.ParentRunner.run(ParentRunner.java:


363

)

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.reflection.ReflectionException: 


Error
 instantiating class com.swjd.po.User 
with
 invalid types () 
or
 values (). Cause: java.lang.NoSuchMethodException: com.swjd.po.User.
<
init
>

()

at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:


86

)

at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:


48

)

at org.apache.ibatis.reflection.factory.DefaultObjectFactory.create(DefaultObjectFactory.java:


41

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:


528

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:


507

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:


331

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:


291

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:


266

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:


236

)

at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:


150

)

at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:


60

)

at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:


73

)

at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:


60

)

at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:


267

)

at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:


137

)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:


96

)

at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:


77

)

at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:


108

)

     MyBatis出现org.apache.ibatis.executor.ExecutorException异常


25

more

Caused by: java.lang.NoSuchMethodException: com.swjd.po.User.


<
init
>

()

at java.lang.Class.getConstructor0(Class.java:


3082

)

at java.lang.Class.getDeclaredConstructor(Class.java:


2178

)

at org.apache.ibatis.reflection.factory.DefaultObjectFactory.instantiateClass(DefaultObjectFactory.java:


60

)

     MyBatis出现org.apache.ibatis.executor.ExecutorException异常


42

more

Process finished 


with
 
exit
 code 
-
1

这种错也是同样的问题,

加上无参构造函数就可以了。

当创建对象来接受sql结果时会遍历实体类的构造方法找到与之匹配的,如果实体类中有构造方法了但是参数不匹配的话就会报上述错误,此时添加无参构造方法(默认的构造方法),会走其他方法,

https://blog.csdn.net/qq_35975416/article/details/80488267












原文 

http://www.blogjava.net/fiele/archive/2020/03/25/435304.html

本站部分文章源于互联网,本着传播知识、有益学习和研究的目的进行的转载,为网友免费提供。如有著作权人或出版方提出异议,本站将立即删除。如果您对文章转载有任何疑问请告之我们,以便我们及时纠正。

PS:推荐一个微信公众号: askHarries 或者qq群:474807195,里面会分享一些资深架构师录制的视频录像:有Spring,MyBatis,Netty源码分析,高并发、高性能、分布式、微服务架构的原理,JVM性能优化这些成为架构师必备的知识体系。还能领取免费的学习资源,目前受益良多

转载请注明原文出处:Harries Blog™ » MyBatis出现org.apache.ibatis.executor.ExecutorException异常

赞 (0)
分享到:更多 ()

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址