1.Table design
create table variables
(
id bigint not null comment '主键',
business_key varchar(128) null comment '业务key',
`key` varchar(128) null comment 'Map中的key',
value varchar(255) null comment 'Map中的value',
data_type varchar(32) null comment '数据类型',
created datetime null comment '创建时间',
modified datetime null comment '修改时间',
yn int null comment '数据是否有效,1:有效,0:无效'
)
comment '自定义变量表';
2. Report an error
org.springframework.jdbc.BadSqlGrammarException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: vtgate: http://xxxte-xx3b-xrxdxxe-4p2cf:12301/: target: test_db.0.master, used tablet: xx3b-11225725 (xx.10x.xx.1x): vttablet: 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 'key,value,data_type,created,modified,yn) values ( 100021,null,'xx' at line 1 (errno 1064) (sqlstate 42000) (CallerID: ): Sql: "/* uag::test_db;1x.1x.1xx.1xx:16xx9;1x.2x.3x1.2x4:1xxx24;1x.x5.1xx.60:31x28;enable */ insert into variables (id,business_key,key,value,data_type,created,modified,yn) values ( 100021,null,'orderTime','1691579920000','Long','2023-08-09 19:21:50','2023-08-09 19:21:50',1 )..........
..........
### The error may exist in xxx/core/dao/mapper/xxx/VariablesMapper.java (best guess)
### The error may involve com.xx.xxx.xx..dao.mapper.VariablesMapper.insertBatch-Inline
### The error occurred while setting parameters
### SQL: insert into variables (id,key,value,data_type,created,modified,yn) values ( ?,?,?,?,?,?,? ),( ?,?,?,?,?,?,? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: vtgate: http://xxxte-xx3b-xrxdxxe-4p2cf:12301/: target: test_db.0.master, used tablet: xxx: vttablet: 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 'key,value,data_type,created,modified,yn) values ( 100021,null,'orderTime' at line 1 (errno 1064) (sqlstate 42000) (CallerID: ):
3. Analysis of error reasons:
After searching for a long time, I found that there was nothing wrong. Finally, after browsing a lot of documents, I decided to debug locally to see if it was caused by a conflict between the field name and the keyword. After changing the field name, it worked immediately.
The key field conflicts with the keywords in MySQL. Just change the key to another name, such as data_key.