mybatis+springmvc+sqlite一个累心的问题:不在纠结

简介: mybatis+springmvc+sqlite一个累心的问题:不在纠结1 java.sql.SQLException: NYI2 org.sqlite.RS.getColumnClassName(RS.


mybatis+springmvc+sqlite一个累心的问题:不在纠结

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: NYI
	org.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.cnblogs.com/rojas/p/4001510.html





目录
相关文章
|
6月前
SpringMVC+Mybatis两个数据源实现(二)
SpringMVC+Mybatis两个数据源实现(二)
|
6月前
SpringMVC+Mybatis两个数据源实现(一)
SpringMVC+Mybatis两个数据源实现(一)
|
6月前
|
SQL JavaScript Java
springboot+springm vc+mybatis实现增删改查案例!
springboot+springm vc+mybatis实现增删改查案例!
|
6月前
|
SQL Java 数据库连接
挺详细的spring+springmvc+mybatis配置整合|含源代码
挺详细的spring+springmvc+mybatis配置整合|含源代码
|
6月前
|
Java 关系型数据库 MySQL
基于ssm实现图书商城(spring+springmvc+mybatis)
基于ssm实现图书商城(spring+springmvc+mybatis)
|
6月前
|
Java 数据库 数据安全/隐私保护
基于SSM框架实现管科类考研自我管理系统(分前后台spring+springmvc+mybatis+maven+jsp+jquery)
基于SSM框架实现管科类考研自我管理系统(分前后台spring+springmvc+mybatis+maven+jsp+jquery)
|
2月前
|
缓存 前端开发 Java
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
Soring Boot的起步依赖、启动流程、自动装配、常用的注解、Spring MVC的执行流程、对MVC的理解、RestFull风格、为什么service层要写接口、MyBatis的缓存机制、$和#有什么区别、resultType和resultMap区别、cookie和session的区别是什么?session的工作原理
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
|
5月前
|
安全 前端开发 Java
挑战5分钟内基于Springboot+SpringMVC+Mybatis-plus快速构建web后端三层架构
挑战5分钟内基于Springboot+SpringMVC+Mybatis-plus快速构建web后端三层架构
50 1
|
5月前
|
Java 程序员
浅浅纪念花一个月完成Springboot+Mybatis+Springmvc+Vue2+elementUI的前后端交互入门项目
浅浅纪念花一个月完成Springboot+Mybatis+Springmvc+Vue2+elementUI的前后端交互入门项目
47 1
|
5月前
|
缓存 NoSQL Java
在 SSM 架构(Spring + SpringMVC + MyBatis)中,可以通过 Spring 的注解式缓存来实现 Redis 缓存功能
【6月更文挑战第18天】在SSM(Spring+SpringMVC+MyBatis)中集成Redis缓存,涉及以下步骤:添加Spring Boot的`spring-boot-starter-data-redis`依赖;配置Redis连接池(如JedisPoolConfig)和连接工厂;在Service层使用`@Cacheable`注解标记缓存方法,指定缓存名和键生成策略;最后,在主配置类启用缓存注解。通过这些步骤,可以利用Spring的注解实现Redis缓存。
74 2