Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mybatis 多个参数的insert报错 #2122

Closed
kagowu opened this issue Mar 28, 2019 · 1 comment
Closed

mybatis 多个参数的insert报错 #2122

kagowu opened this issue Mar 28, 2019 · 1 comment

Comments

@kagowu
Copy link

kagowu commented Mar 28, 2019

Bug Report

版本

	<dependency>
		<groupId>io.shardingsphere</groupId>
		<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
		<version>3.1.0</version>
	</dependency>

mysql-connect-java 5.1.41
mybatis 3.4.0

现象

我使用的是mybatis
数据库是 mysql
mybatis的java mapper代码:
int saveSyncPropertys(@param("propertys") List propertys,@param("updatedTime") Date updatedTime);

mybatis的xml 配置文件(此处省略了其他字段):

insert into ms_property(companyUuid,createdTime) VALUES

(#{obj.companyUuid},
,#{updatedTime})

ON DUPLICATE KEY UPDATE
updatedTime=#{updatedTime},

报错

Caused by: java.sql.SQLException: No value specified for parameter 149
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2211)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2191)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2121)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1162)
at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
at io.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:63)
at io.shardingsphere.shardingjdbc.executor.SQLExecuteCallbackFactory$2.executeSQL(SQLExecuteCallbackFactory.java:59)
at io.shardingsphere.core.executor.sql.execute.SQLExecuteCallback.execute0(SQLExecuteCallback.java:72)
at io.shardingsphere.core.executor.sql.execute.SQLExecuteCallback.execute(SQLExecuteCallback.java:61)
at io.shardingsphere.core.executor.ShardingExecuteEngine.syncGroupExecute(ShardingExecuteEngine.java:175)
at io.shardingsphere.core.executor.ShardingExecuteEngine.groupExecute(ShardingExecuteEngine.java:152)
at io.shardingsphere.core.executor.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:71)
at io.shardingsphere.core.executor.sql.execute.SQLExecuteTemplate.executeGroup(SQLExecuteTemplate.java:54)
at io.shardingsphere.shardingjdbc.executor.AbstractStatementExecutor.executeCallback(AbstractStatementExecutor.java:114)
at io.shardingsphere.shardingjdbc.executor.PreparedStatementExecutor.execute(PreparedStatementExecutor.java:148)
at io.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:137)
at io.opentracing.contrib.jdbc.TracingPreparedStatement.execute(TracingPreparedStatement.java:177)
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)

换种写法

insert into ms_property(companyUuid,createdTime) VALUES (#{obj.companyUuid}, ,#{updatedTime}) ON DUPLICATE KEY UPDATE updatedTime=**CURRENT_DATE**

就没有问题了。

所以关键是最后这个@param("updatedTime") 莫名其妙丢失了。

检查了底层的方法
com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2211)

batchedParameterStrings.length=149
但是第149个元素是null:
batchedParameterStrings[148]=null

@terrymanu
Copy link
Member

For English only, other languages will not accept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants