如何使用 Prepare 语句 JDBC 在 MySQL 中以 varchar 和 json 格式插入值?
How to Insert value in varchar as well as in json format in MySQL using Prepare Statement JDBC?
Table Schema: CREATE TABLE `book` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`tags` json DEFAULT NULL,
PRIMARY KEY (`id`)
)
其中标题的值为 'ECMAScript 2015: A SitePoint Anthology'
,标签的值为 json 数组 '["JavaScript", "ES2015", "JSON"]'
insertStatement.setObject(n++, new Gson().toJson(pii.getEmails()));
Table Schema: CREATE TABLE `book` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL,
`tags` json DEFAULT NULL,
PRIMARY KEY (`id`)
)
其中标题的值为 'ECMAScript 2015: A SitePoint Anthology'
,标签的值为 json 数组 '["JavaScript", "ES2015", "JSON"]'
insertStatement.setObject(n++, new Gson().toJson(pii.getEmails()));