1 java.sql.SQLException: NYI
2 org.sqlite.RS.getColumnClassName(RS.java:269)
在配置mybatis+springmvc+sqlite时候,
<insert id="saveUser" parameterType="User" keyProperty="id" useGeneratedKeys="false" > <selectKey keyProperty="id" resultType="int" order="BEFORE"> SELECT seq+1 as seq FROM sqlite_sequence WHERE (name = 't_demo') //sqlite 不会自动加1,所以手动了 </selectKey> insert into t_demo (id,name,age,sex)values(#{id},#{name},#{age},#{sex}) </insert>
遭遇到一下问题:
1 root cause
org.springframework.jdbc.UncategorizedSQLException: Error selecting key or setting result to parameter object. Cause: java.sql.SQLException: NYI; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; NYI; nested exception is java.sql.SQLException: NYI
2 root cause
java.sql.SQLException: NYIorg.sqlite.RS.getColumnClassName(RS.java:269)
因为网上关于SQLite的整合资料较少(什么百度 谷歌,搜遍了,连mybatis官网的例子都看了),所以自己就折腾,大概有4天吧,每天看到这个错误,已经不烦了,已经到快吐了。
在配置mybatis的mapper.xml中需要配置 insert语句,而ID自增是最大的问题,PostgreSQL版的我已经搞定,想着
SQLite应该类似,结果始终是报错,具体:
1 type Exception report 2 3 message 4 5 description The server encountered an internal error () that prevented it from fulfilling this request. 6 7 exception 8 9 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Error selecting key or setting result to parameter object. Cause: java.sql.SQLException: NYI 10 ; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; NYI; nested exception is java.sql.SQLException: NYI 11 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656) 12 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) 13 javax.servlet.http.HttpServlet.service(HttpServlet.java:641) 14 javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 15 16 17 root cause 18 19 org.springframework.jdbc.UncategorizedSQLException: Error selecting key or setting result to parameter object. Cause: java.sql.SQLException: NYI 20 ; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; NYI; nested exception is java.sql.SQLException: NYI 21 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83) 22 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 23 org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) 24 org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71) 25 org.mybatis.spring.SqlsessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365) 26 com.sun.proxy.$Proxy10.insert(Unknown Source) 27 org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237) 28 com.sinaapp.mydemo27.daoimpl.UserDaoImpl.inseartUser(UserDaoImpl.java:20) 29 com.sinaapp.mydemo27.service.UserService.insertUser(UserService.java:30) 30 com.sinaapp.mydemo27.service.UserService$$FastClassByCGLIB$$8193c93a.invoke(<generated>) 31 net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) 32 org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) 33 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 34 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 35 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 36 org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) 37 com.sinaapp.mydemo27.service.UserService$$EnhancerByCGLIB$$3e2827df.insertUser(<generated>) 38 com.sinaapp.mydemo27.controller.UserController.handleInseart(UserController.java:55) 39 sun.reflect.NativeMethodaccessorImpl.invoke0(Native Method) 40 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 41 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 42 java.lang.reflect.Method.invoke(Unknown Source) 43 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176) 44 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426) 45 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414) 46 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790) 47 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) 48 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) 49 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560) 50 javax.servlet.http.HttpServlet.service(HttpServlet.java:641) 51 javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 52 53 54 root cause 55 56 java.sql.SQLException: NYI 57 org.sqlite.RS.getColumnClassName(RS.java:269) 58 org.apache.ibatis.executor.resultset.FastResultSetHandler$ResultColumnCache.<init>(FastResultSetHandler.java:585) 59 org.apache.ibatis.executor.resultset.FastResultSetHandler.handleResultSets(FastResultSetHandler.java:151) 60 org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:57) 61 org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:70) 62 org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:57) 63 org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) 64 org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141) 65 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) 66 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) 67 org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:65) 68 org.apache.ibatis.executor.keygen.SelectKeyGenerator.processBefore(SelectKeyGenerator.java:41) 69 org.apache.ibatis.executor.statement.BaseStatementHandler.generateKeys(BaseStatementHandler.java:127) 70 org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:60) 71 org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:36) 72 org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:42) 73 org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:348) 74 org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:43) 75 org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108) 76 org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75) 77 org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145) 78 org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134) 79 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 80 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 81 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 82 java.lang.reflect.Method.invoke(Unknown Source) 83 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355) 84 com.sun.proxy.$Proxy10.insert(Unknown Source) 85 org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237) 86 com.sinaapp.mydemo27.daoimpl.UserDaoImpl.inseartUser(UserDaoImpl.java:20) 87 com.sinaapp.mydemo27.service.UserService.insertUser(UserService.java:30) 88 com.sinaapp.mydemo27.service.UserService$$FastClassByCGLIB$$8193c93a.invoke(<generated>) 89 net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) 90 org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688) 91 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 92 org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 93 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 94 org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) 95 com.sinaapp.mydemo27.service.UserService$$EnhancerByCGLIB$$3e2827df.insertUser(<generated>) 96 com.sinaapp.mydemo27.controller.UserController.handleInseart(UserController.java:55) 97 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 98 sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 99 sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)100 java.lang.reflect.Method.invoke(Unknown Source)101 org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)102 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)103 org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)104 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)105 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)106 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)107 org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)108 javax.servlet.http.HttpServlet.service(HttpServlet.java:641)109 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
快心死的时候,都去
https://code.google.com/p/sqlite-jdbc/source/browse/src/main/java/org/sqlite/RS.java?r=e74939879270122b724d6fd62d8c40aa70870fcf
看了SQLite jdbc的source,结果只发现下面这句,于是把resultType类型改成 “Object”,结果还是报错。
public String getColumnClassName(int col) throws SQLException { checkCol(col); return "java.lang.Object"; }
绝望了,不过 突然想到 要不要去 findjar.com上找个新的SQLite-jdbc 驱动,于是
http://www.findjar.com/index.x?query=sqlite
找到了最新版本“sqlite-jdbc-3.6.14.1.jar” 结果令人惊喜的事发生了,
报错不再是java.sql.SQLException: NYI,
换 parameterTypeMissMatch,这个把resultType类型改回去int,再跑,以为会ok,
出人意料的是,又报错,不过这个错我是知道的,sql主键唯一的错误,原来SQLite的ID自增是假的,就不自增,只是记录而已,要自己手动加。
修改自增后,测试没有问题了。
一个字,心累,share防止有同样问题的人在此纠结。
若转载请标注 :转自 博客园 :http://www.VEVb.com/rojas/p/4001510.html
新闻热点
疑难解答