0
我想从模型插入表中,但出现以下错误。如何在弹簧启动时从模型插入数据表
There was an unexpected error (type=Internal Server Error, status=500).
StatementCallback; bad SQL grammar [INSERT INTO user_sample(user_id) VALUES(?); sampleid]; nested exception is java.sql.BatchUpdateException: 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 'sampleid' at line
这里是我的代码:
public class UserInfo {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
创建一个表:
CREATE TABLE `user_sample` (
`user_partner_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`user_partner_id`)
) ENGINE=InnoDB AUTO_INCREMENT=77182 DEFAULT CHARSET=utf8;
这里是将数据插入到表中的代码。
public void insertValues(@ModelAttribute USerInfo userInfo){
jdbcTemplate.batchUpdate("INSERT INTO user_sample(user_id) VALUES(?)", userInfo.getId());
}
什么语句用来从模型中插入数据?