모델에서 테이블에 삽입하려고하는데 다음과 같은 오류가 발생합니다. 봄 부팅시 모델에서 테이블로 데이터를 삽입하는 방법
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;
테이블에 데이터를 삽입하는 코드입니다
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 void insertValues(@ModelAttribute USerInfo userInfo){
jdbcTemplate.batchUpdate("INSERT INTO user_sample(user_id) VALUES(?)", userInfo.getId());
}
모델의 데이터를 삽입하는 데 사용할 수있는 구문은 무엇입니까? 당신이 그것을 당신이 사용하는 것이 좋습니다 방법의 종류를 수행 할 경우 NamedParameterJdbcTemplate
는 예를 들어 있습니다 https://spring.io/guides/gs/accessing-data-jpa/