使用mybatis插入单表多行数据时,报错 TDengine ERROR (216): Syntax error in SQL
Bug Description 使用mybatis插入单表多行数据时,报错 TDengine ERROR (216): Syntax error in SQL 插入单表单行和多表单行时正常。
To Reproduce Steps to reproduce the behavior:
- 运行 官方springbootdemo
- 测试 Weather的多行插入
Expected Behavior A clear and concise description of what you expected to happen.
Screenshots 2021-11-22 15:12:47.346 DEBUG 15728 --- [nio-8081-exec-3] c.t.e.s.dao.WeatherMapper.insertBatch : ==> Preparing: insert into test.t? (ts, temperature, humidity, note) values (?, ?, ?, ?) (?, ?, ?, ?) 2021-11-22 15:12:47.346 DEBUG 15728 --- [nio-8081-exec-3] c.t.e.s.dao.WeatherMapper.insertBatch : ==> Parameters: 1(Integer), 2021-11-22 15:12:47.327(Timestamp), 3.0(Float), 5.0(Float), null, 2021-11-22 15:12:47.327(Timestamp), 3.0(Float), 5.0(Float), null 2021-11-22 15:12:47.400 ERROR 15728 --- [nio-8081-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException:
Error updating database. Cause: java.sql.SQLException: TDengine ERROR (216): Syntax error in SQL
The error may exist in com/taosdata/example/springbootdemo/dao/WeatherMapper.xml
The error may involve com.taosdata.example.springbootdemo.dao.WeatherMapper.insertBatch-Inline
The error occurred while setting parameters
SQL: insert into test.t? (ts, temperature, humidity, note) values (?, ?, ?, ?) (?, ?, ?, ?)
Cause: java.sql.SQLException: TDengine ERROR (216): Syntax error in SQL
; uncategorized SQLException; SQL state []; error code [534]; TDengine ERROR (216): Syntax error in SQL; nested exception is java.sql.SQLException: TDengine ERROR (216): Syntax error in SQL] with root cause
java.sql.SQLException: TDengine ERROR (216): Syntax error in SQL at com.taosdata.jdbc.TSDBError.createSQLException(TSDBError.java:75) ~[taos-jdbcdriver-2.0.34.jar:na] at com.taosdata.jdbc.rs.RestfulStatement.executeOneUpdate(RestfulStatement.java:122) ~[taos-jdbcdriver-2.0.34.jar:na] at com.taosdata.jdbc.rs.RestfulStatement.execute(RestfulStatement.java:82) ~[taos-jdbcdriver-2.0.34.jar:na]
Environment (please complete the following information):
- CentOS 7.0
- TDengine 版本 Version:2.2.1.1
- taos-jdbcdriver 版本 2.0.34 使用RestfulDriver连接
Additional Context
int insertBatch(@Param("groupId") int groupId,@Param("weathers") List<Weather> weathers);

<insert id="insertBatch" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
insert into test.t#{groupId} (ts, temperature, humidity, note)
values
<foreach collection="weathers" item="weather">
(#{weather.ts}, #{weather.temperature}, #{weather.humidity}, #{weather.note})
</foreach>
</insert>
use this:
<insert id="insertBatch" parameterType="com.taosdata.example.springbootdemo.domain.Weather">
insert into test.t#{groupId} (ts, temperature, humidity, note)
values
<foreach collection="weathers" item="weather" separator=",">
(#{weather.ts}, #{weather.temperature}, #{weather.humidity}, #{weather.note})
</foreach>
</insert>
( ̄工 ̄lll)可以了(//▽//),官方文档中的示例都是不用逗号分隔的,建议给出明确提示