1.表設計?
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.報錯
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.報錯原因分析:
找了半天發現也沒有啥錯,最后通過瀏覽大量文檔,決定本地調試下看看是不是字段名稱與關鍵字沖突導致的,改了字段名稱后立馬好使了。
key這個字段與MySQL中的關鍵字有沖突,將key改為其它名稱,比如data_key就可以了。