为了账号安全,请及时绑定邮箱和手机立即绑定

Error querying database. Cause: java.sql.SQLException: Unexpected exception encountered during query.

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Unexpected exception encountered during query.
### The error may exist in com/imooc/config/sqlxml/Message.xml
### The error may involve Message.queryMessageList
### The error occurred while executing a query
### Cause: java.sql.SQLException: Unexpected exception encountered during query.
	org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
	com.imooc.Dao.MessageDao.queryMessageList(MessageDao.java:31)
	com.imooc.service.ListService.queryMessageList(ListService.java:25)
	com.imooc.serlvet.ListServlet.doGet(ListServlet.java:43)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.sql.SQLException: Unexpected exception encountered during query.
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
	com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2664)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
	com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)
	com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3868)
	com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3407)
	com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2384)
	com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
	com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
	com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
	com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
	java.sql.DriverManager.getConnection(DriverManager.java:664)
	java.sql.DriverManager.getConnection(DriverManager.java:208)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
	org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
	org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
	org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)
	org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
	com.imooc.Dao.MessageDao.queryMessageList(MessageDao.java:31)
	com.imooc.service.ListService.queryMessageList(ListService.java:25)
	com.imooc.serlvet.ListServlet.doGet(ListServlet.java:43)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.lang.ArrayIndexOutOfBoundsException: 255
	com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3100)
	com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2107)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2618)
	com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
	com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1557)
	com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3868)
	com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3407)
	com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2384)
	com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
	com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
	com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
	com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
	com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
	java.sql.DriverManager.getConnection(DriverManager.java:664)
	java.sql.DriverManager.getConnection(DriverManager.java:208)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
	org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
	org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
	org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
	org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
	org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)
	org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
	org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
	org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
	org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
	org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
	com.imooc.Dao.MessageDao.queryMessageList(MessageDao.java:31)
	com.imooc.service.ListService.queryMessageList(ListService.java:25)
	com.imooc.serlvet.ListServlet.doGet(ListServlet.java:43)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

MessageDao.java

https://img1.sycdn.imooc.com//5c6a27e70001cdec08400403.jpg

Configuration.xml

https://img1.sycdn.imooc.com//5c6a27e7000116c508580333.jpg

Message.xml

https://img1.sycdn.imooc.com//5c6a27e7000177bb07620255.jpg

DBAccess.java

https://img1.sycdn.imooc.com//5c6a28c90001d07c08490243.jpg

SQL语句没有问题,在数据库中正常运行

有没有可能是mysql-jdbc和Mybatis版本不匹配,或者MySQL和Mybatis版本不匹配?


正在回答

1 回答

问题已解决,是Mybatis和mysql-connector-java版本冲突,使用Mybatis 3.4.6和mysql-connector-java 5.1.47解决问题。

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Error querying database. Cause: java.sql.SQLException: Unexpected exception encountered during query.

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信