这次看到好多朋友在数据库添加数据时报的一些异常,今天特意写了一个测试附加解决办法,写下来希望能够帮到大家。
控制台详细信息
六月 07, 2017 11:18:11 上午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@48778a5d: startup date [Wed Jun 07 11:18:11 CST 2017]; root of context hierarchy
六月 07, 2017 11:18:11 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [D:\Users\Administrator\workspace\carRent\build\classes\applicationContext-dao.xml]
六月 07, 2017 11:18:11 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [D:\Users\Administrator\workspace\carRent\build\classes\applicationContext-service.xml]
六月 07, 2017 11:18:12 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from file [D:\Users\Administrator\workspace\carRent\build\classes\applicationContext-transaction.xml]
六月 07, 2017 11:18:12 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [springmvc.xml]
六月 07, 2017 11:18:12 上午 org.springframework.context.support.PropertySourcesPlaceholderConfigurer loadProperties
信息: Loading properties file from class path resource [jdbc.properties]
2017-06-07 11:18:14,673 DEBUG [main] logging.LogFactory (LogFactory.java:128) - Logging initialized using 'class org.apache.ibatis.logging.log4j2.Log4j2Impl' adapter.
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/addCars.do],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.carManage.controller.CarManageController.addCars(cn.sxt.carRent.pojo.Cars,javax.servlet.http.HttpSession,org.springframework.web.multipart.MultipartFile[])
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/selectCars.do],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.carManage.controller.CarManageController.findCars(cn.sxt.carRent.pojo.CarsQuery,org.springframework.ui.Model,javax.servlet.http.HttpServletRequest)
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/userLogin],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.carRent.controller.UserLoginController.userLogin(javax.servlet.http.HttpSession,cn.sxt.carRent.pojo.Users,org.springframework.ui.Model)
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/addCusto.do],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.custoManager.controller.CustoManagerController.addCusto(cn.sxt.carRent.pojo.Customers,javax.servlet.http.HttpSession)
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/selectCIndentity],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.operationManage.controller.RentTableController.selectCIndentity(javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException
六月 07, 2017 11:18:15 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
信息: Mapped "{[/selectRentCars],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String cn.sxt.operationManage.controller.RentTableController.selectRentCars(org.springframework.ui.Model)
六月 07, 2017 11:18:16 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
信息: Looking for @ControllerAdvice: org.springframework.context.support.ClassPathXmlApplicationContext@48778a5d: startup date [Wed Jun 07 11:18:11 CST 2017]; root of context hierarchy
六月 07, 2017 11:18:16 上午 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
信息: Looking for @ControllerAdvice: org.springframework.context.support.ClassPathXmlApplicationContext@48778a5d: startup date [Wed Jun 07 11:18:11 CST 2017]; root of context hierarchy
2017-06-07 11:18:16,440 INFO [main] util.BaseTest (BaseTest.java:17) - ---before---
2017-06-07 11:18:16,440 INFO [main] test.CustoManagerTest (CustoManagerTest.java:26) - 这是测试类
custoManagerServiceImpl.saveCustomerService(添加客户业务层开始)
2017-06-07 11:18:16,459 DEBUG [main] spring.SqlSessionUtils (SqlSessionUtils.java:97) - Creating a new SqlSession
2017-06-07 11:18:16,468 DEBUG [main] spring.SqlSessionUtils (SqlSessionUtils.java:148) - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@34133979] was not registered for synchronization because synchronization is not active
六月 07, 2017 11:18:16 上午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} inited
2017-06-07 11:18:16,990 DEBUG [main] transaction.SpringManagedTransaction (SpringManagedTransaction.java:87) - JDBC Connection [oracle.jdbc.driver.T4CConnection@595b5054] will not be managed by Spring
2017-06-07 11:18:17,002 DEBUG [main] jdbc.BaseJdbcLogger (BaseJdbcLogger.java:139) - ==> Preparing: insert into buff.customers (identity, custname, sex, address, phone, career) values (?,?,?,?,?,?) returning rowid into :nav_rowid
2017-06-07 11:18:17,149 DEBUG [main] jdbc.BaseJdbcLogger (BaseJdbcLogger.java:139) - ==> Parameters: 22(Integer), 艾希(String), 0(Integer), 艾欧尼亚(String), 1546543215(String), ADC(String)
2017-06-07 11:18:17,164 DEBUG [main] spring.SqlSessionUtils (SqlSessionUtils.java:191) - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@34133979]
六月 07, 2017 11:18:17 上午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource[org/springframework/jdbc/support/sql-error-codes.xml]
六月 07, 2017 11:18:17 上午 org.springframework.jdbc.support.SQLErrorCodesFactory
信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2017-06-07 11:18:17,259 INFO [main] util.BaseTest (BaseTest.java:30) - --close--
六月 07, 2017 11:18:17 上午 org.springframework.context.support.ClassPathXmlApplicationContext doClose
信息: Closing org.springframework.context.support.ClassPathXmlApplicationContext@48778a5d: startup date [Wed Jun 07 11:18:11 CST 2017]; root of context hierarchy
六月 07, 2017 11:18:17 上午 com.alibaba.druid.pool.DruidDataSource info
信息: {dataSource-1} closed
使用Junit测试时报错代码如下
org.springframework.jdbc.UncategorizedSQLException:
### Error updating database. Cause: java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 7
### The error may involve cn.sxt.custoManager.dao.CustoManagerDao.saveCustomer-Inline
### The error occurred while setting parameters
### SQL: insert into buff.customers (identity, custname, sex, address, phone, career) values (?,?,?,?,?,?) returning rowid into :nav_rowid
### Cause: java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 7
; uncategorized SQLException for SQL []; SQL state [null]; error code [17041]; 索引中丢失 IN 或 OUT 参数:: 7; nested exception is java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 7
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
解决方案:
根据错误提示,和前辈种种的碰壁,归结为两点:
(1) 索引是否有问题?(“索引中丢失”)
(2) 字段赋值是否与数据库字段类型匹配?
本次测试是应为sql测试语句出错了。
useGeneratedKeys="true" keyColumn="identity" keyProperty="identity">
insert into buff.customers (identity, custname, sex, address, phone, career)
values (#{ identity},#{ custname},#{ sex},#{ address},#{ phone},#{ career})
returning rowid into :nav_rowid
returning rowid into :nav_rowid
这句oracle数据库在搜索是自行增加的一个索引,这样按索引搜索是速度比较快,而我们在向数据库添加数据时不能带这句sql语句,去掉就行了,