创建订单-单侧报错
来源:13-7 创建订单-单测

不停跳动的空指针
2020-04-09
org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values ( 1, 1586411387879, 26, 'Apple' at line 3 ### The error may exist in file [/Users/linwei/IdeaProjects/linwei/mall/target/classes/mappers/OrderItemMapper.xml] ### The error may involve com.imooc.mall.dao.OrderItemMapper.batchInsert-Inline ### The error occurred while setting parameters ### SQL: insert into mall_order_item (user_id, order_no, product_id, product_name, product_image, current_unit_price, quantity, total_price,) values ( ?, ?, ?, ?, ?, ?, ?, ? ) ### Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values ( 1, 1586411387879, 26, 'Apple' at line 3 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values ( 1, 1586411387879, 26, 'Apple' at line 3 at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:234) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) at com.sun.proxy.$Proxy77.insert(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:57) at com.sun.proxy.$Proxy86.batchInsert(Unknown Source) at com.imooc.mall.service.impl.OrderServiceImpl.create(OrderServiceImpl.java:109) at com.imooc.mall.service.impl.OrderServiceImpl$$FastClassBySpringCGLIB$$59b4e2de.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:295) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.imooc.mall.service.impl.OrderServiceImpl$$EnhancerBySpringCGLIB$$cbe6c757.create() at com.imooc.mall.service.IOrderServiceTest.create(IOrderServiceTest.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values ( 1, 1586411387879, 26, 'Apple' at line 3 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370) at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy113.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy111.update(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ... 47 more
写回答
3回答
-
廖师兄助理
2020-04-29
你的batchInsert的sql需要的参数和你实际单测传的数量不一致
00 -
不停跳动的空指针
提问者
2020-04-09
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.imooc.mall.dao.OrderItemMapper"> <resultMap id="BaseResultMap" type="com.imooc.mall.pojo.OrderItem"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="user_id" jdbcType="INTEGER" property="userId" /> <result column="order_no" jdbcType="BIGINT" property="orderNo" /> <result column="product_id" jdbcType="INTEGER" property="productId" /> <result column="product_name" jdbcType="VARCHAR" property="productName" /> <result column="product_image" jdbcType="VARCHAR" property="productImage" /> <result column="current_unit_price" jdbcType="DECIMAL" property="currentUnitPrice" /> <result column="quantity" jdbcType="INTEGER" property="quantity" /> <result column="total_price" jdbcType="DECIMAL" property="totalPrice" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> </resultMap> <sql id="Base_Column_List"> id, user_id, order_no, product_id, product_name, product_image, current_unit_price, quantity, total_price, create_time, update_time </sql> <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from mall_order_item where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> delete from mall_order_item where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="com.imooc.mall.pojo.OrderItem"> insert into mall_order_item (id, user_id, order_no, product_id, product_name, product_image, current_unit_price, quantity, total_price, create_time, update_time) values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{orderNo,jdbcType=BIGINT}, #{productId,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productImage,jdbcType=VARCHAR}, #{currentUnitPrice,jdbcType=DECIMAL}, #{quantity,jdbcType=INTEGER}, #{totalPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}) </insert> <insert id="insertSelective" parameterType="com.imooc.mall.pojo.OrderItem"> insert into mall_order_item <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="userId != null"> user_id, </if> <if test="orderNo != null"> order_no, </if> <if test="productId != null"> product_id, </if> <if test="productName != null"> product_name, </if> <if test="productImage != null"> product_image, </if> <if test="currentUnitPrice != null"> current_unit_price, </if> <if test="quantity != null"> quantity, </if> <if test="totalPrice != null"> total_price, </if> <if test="createTime != null"> create_time, </if> <if test="updateTime != null"> update_time, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=INTEGER}, </if> <if test="userId != null"> #{userId,jdbcType=INTEGER}, </if> <if test="orderNo != null"> #{orderNo,jdbcType=BIGINT}, </if> <if test="productId != null"> #{productId,jdbcType=INTEGER}, </if> <if test="productName != null"> #{productName,jdbcType=VARCHAR}, </if> <if test="productImage != null"> #{productImage,jdbcType=VARCHAR}, </if> <if test="currentUnitPrice != null"> #{currentUnitPrice,jdbcType=DECIMAL}, </if> <if test="quantity != null"> #{quantity,jdbcType=INTEGER}, </if> <if test="totalPrice != null"> #{totalPrice,jdbcType=DECIMAL}, </if> <if test="createTime != null"> #{createTime,jdbcType=TIMESTAMP}, </if> <if test="updateTime != null"> #{updateTime,jdbcType=TIMESTAMP}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="com.imooc.mall.pojo.OrderItem"> update mall_order_item <set> <if test="userId != null"> user_id = #{userId,jdbcType=INTEGER}, </if> <if test="orderNo != null"> order_no = #{orderNo,jdbcType=BIGINT}, </if> <if test="productId != null"> product_id = #{productId,jdbcType=INTEGER}, </if> <if test="productName != null"> product_name = #{productName,jdbcType=VARCHAR}, </if> <if test="productImage != null"> product_image = #{productImage,jdbcType=VARCHAR}, </if> <if test="currentUnitPrice != null"> current_unit_price = #{currentUnitPrice,jdbcType=DECIMAL}, </if> <if test="quantity != null"> quantity = #{quantity,jdbcType=INTEGER}, </if> <if test="totalPrice != null"> total_price = #{totalPrice,jdbcType=DECIMAL}, </if> <if test="createTime != null"> create_time = #{createTime,jdbcType=TIMESTAMP}, </if> <if test="updateTime != null"> update_time = #{updateTime,jdbcType=TIMESTAMP}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="com.imooc.mall.pojo.OrderItem"> update mall_order_item set user_id = #{userId,jdbcType=INTEGER}, order_no = #{orderNo,jdbcType=BIGINT}, product_id = #{productId,jdbcType=INTEGER}, product_name = #{productName,jdbcType=VARCHAR}, product_image = #{productImage,jdbcType=VARCHAR}, current_unit_price = #{currentUnitPrice,jdbcType=DECIMAL}, quantity = #{quantity,jdbcType=INTEGER}, total_price = #{totalPrice,jdbcType=DECIMAL}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} </update> <insert id="batchInsert" parameterType="list"> insert into mall_order_item (user_id, order_no, product_id, product_name, product_image, current_unit_price, quantity, total_price,) values <foreach collection="orderItemList" index="index" item="item" separator=","> ( #{item.userId}, #{item.orderNo}, #{item.productId}, #{item.productName}, #{item.productImage}, #{item.currentUnitPrice}, #{item.quantity}, #{item.totalPrice} ) </foreach> </insert> </mapper>
00 -
廖师兄助理
2020-04-09
### The error may exist in file [/Users/linwei/IdeaProjects/linwei/mall/target/classes/mappers/OrderItemMapper.xml] 请把这个文件的截图发我下
012020-04-09
相似问题
创建订单报错了
回答 3
关于写入数据库订单号重复
回答 1