关于SSM中mybatis向oracle添加语句采用序列自增的问题

在SSM向oracle数据库中插入语句时,报错如下:

### Error updating database.  Cause: java.sql.SQLException: 不支持的特性

### SQL: insert into standard(id,zhname,version,keys,release_date,impl_date,ackage_path)   values(seq_id.nextval,?,?,?,?,?,?)

### Cause: java.sql.SQLException: 不支持的特性

; uncategorized SQLException for SQL []; SQL state [null]; error code [17023]; 不支持的特性; nested exception is java.sql.SQLException: 不支持的特性

- (8768 ms) - [DEBUG] 2018-03-03 17:08:49,999 org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [com.yusys.controller.StandardController@6adb953c]: org.springframework.jdbc.UncategorizedSQLException:

### Error updating database.  Cause: java.sql.SQLException: 不支持的特性

### SQL: insert into standard(id,zhname,version,keys,release_date,impl_date,ackage_path)   values(seq_id.nextval,?,?,?,?,?,?)

### Cause: java.sql.SQLException: 不支持的特性

; uncategorized SQLException for SQL []; SQL state [null]; error code [17023]; 不支持的特性; nested exception is java.sql.SQLException: 不支持的特性

- (8769 ms) - [DEBUG] 2018-03-03 17:08:50,000 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [com.yusys.controller.StandardController@6adb953c]: org.springframework.jdbc.UncategorizedSQLException:

### Error updating database.  Cause: java.sql.SQLException: 不支持的特性

### SQL: insert into standard(id,zhname,version,keys,release_date,impl_date,ackage_path)   values(seq_id.nextval,?,?,?,?,?,?)

### Cause: java.sql.SQLException: 不支持的特性

; uncategorized SQLException for SQL []; SQL state [null]; error code [17023]; 不支持的特性; nested exception is java.sql.SQLException: 不支持的特性

- (8769 ms) - [DEBUG] 2018-03-03 17:08:50,000 org.springframework.web.multipart.commons.CommonsMultipartResolver - Cleaning up multipart file [file] with original filename [3.jpg], stored at [D:\java软件安装资源汇总\apache-tomcat-7.0.67\work\Catalina\localhost\standardSystem\upload_a2e87d6c_1c40_4a5f_bc8f_591e429a8a30_00000005.tmp]

- (8771 ms) - [DEBUG] 2018-03-03 17:08:50,002 org.springframework.web.servlet.DispatcherServlet - Could not complete request

org.springframework.jdbc.UncategorizedSQLException:

### Error updating database.  Cause: java.sql.SQLException: 不支持的特性

### SQL: insert into standard(id,zhname,version,keys,release_date,impl_date,ackage_path)   values(seq_id.nextval,?,?,?,?,?,?)

### Cause: java.sql.SQLException: 不支持的特性

; uncategorized SQLException for SQL []; SQL state [null]; error code [17023]; 不支持的特性; nested exception is java.sql.SQLException: 不支持的特性

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:90)

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:82)

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

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

    at com.sun.proxy.$Proxy8.insert(Unknown Source)

    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)

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

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

    at com.sun.proxy.$Proxy15.add(Unknown Source)

    at com.yusys.service.StandardServiceImpl.add(StandardServiceImpl.java:30)

    at com.yusys.controller.StandardController.add(StandardController.java:159)

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

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)

    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)

    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)

    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)

    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)

    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)

    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)

    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)

    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)

    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)

    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)

    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)

    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

    at java.lang.Thread.run(Unknown Source)

Caused by: java.sql.SQLException: 不支持的特性

    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)

    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)

    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)

    at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:689)

    at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:3360)

    at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:508)

    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:400)

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

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

    at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:55)

    at com.sun.proxy.$Proxy27.prepareStatement(Unknown Source)

    at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:80)

    at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:88)

    at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:59)

    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:85)

    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)

    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)

    at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)

    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)

    at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)

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

    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

    at java.lang.reflect.Method.invoke(Unknown Source)

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

    ... 45 more

解决办法:根据这个现象在网上查了很多,大部分都是说oracle驱动不支持,更换驱动之类的,限于我拥有的驱动资源,不能这么解决,

还查到有人说是:

1、主键没有自增

2、表中字段数据类型与bean中的数据类型不一致,请将数据类型与表中类型一致就可,

这是我突然想到oracle的主键自增与mysql 的主键自增机制不同,故而就是我的mybatis的xml映射语句有问题,于是更改如下:

<!-- 添加 -->
<insert id="add" parameterType="Standard" useGeneratedKeys="true">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
select SEQUENCE_STANDARD.nextval as id from dual
</selectKey>
insert into standard(id,zhname,version,keys,release_date,impl_date,ackage_path)
values(#{id},#{zhname},#{version},#{keys},#{release_date},#{impl_date},#{ackage_path})
</insert>

此时运行,又发现如下报错:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='keys', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy8.insert(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:57)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy15.add(Unknown Source)
at com.yusys.service.StandardServiceImpl.add(StandardServiceImpl.java:30)
at com.yusys.controller.StandardController.add(StandardController.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:180)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='keys', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:89)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.parameterize(PreparedStatementHandler.java:93)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.parameterize(RoutingStatementHandler.java:64)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:49)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
... 45 more
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #4 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:47)
at org.apache.ibatis.scripting.defaults.DefaultParameterHandler.setParameters(DefaultParameterHandler.java:87)
... 58 more
Caused by: java.sql.SQLException: 无效的列类型
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:6164)
at oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:1316)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
at org.apache.commons.dbcp.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
at com.sun.proxy.$Proxy28.setNull(Unknown Source)
at org.apache.ibatis.type.BaseTypeHandler.setParameter(BaseTypeHandler.java:45)
... 59 more

 

查找半天,竟然发现是因为我的页面缺少一个上送字段即input标签,而这个在数据库中是要非空的,ε=(´ο`*)))唉,添加后,该报错消失

posted @ 2018-03-03 17:51  醉逍遥_001  阅读(305)  评论(0编辑  收藏  举报