java jdbctemplate insert语句_JDBCTemplate INSERT INTO语句:无法弄清楚错误

我不能为我的生活找出为什么下面的查询返回此错误消息:

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;

bad SQL grammar [INSERT INTO Survey (survey.PK1, survey.USERS_PK1,

survey.ACCREDITATION_PK1, survey.PRIVACY_TYPE_PK1, survey.EVAL_FORM_PK1,

survey.TITLE, survey.DESCRIPTION, to_date(survey.START_DATE),

survey.START_TIME, to_date(survey.END_DATE), survey.END_TIME,

survey.HAS_GRADECENTER_COLUMN, survey.HAS_ANNOUNCEMENT )

VALUES(survey_SEQ.nextval,?,?,?,?,?,?,?,?,?,?,?,?)];

nested exception is java.sql.SQLSyntaxErrorException: ORA-00917: missing comma 

String sql = "INSERT INTO UHCL_PR_survey " +

"(" +

"PK1, " +

"USERS_PK1, " +

"ACCREDITATION_PK1, " +

"PRIVACY_TYPE_PK1, " +

"EVAL_FORM_PK1, " +

"TITLE, " +

"DESCRIPTION, " +

"to_date(START_DATE), " +

"START_TIME, " +

"to_date(END_DATE), " +

"END_TIME, " +

"HAS_GRADECENTER_COLUMN, " +

"HAS_ANNOUNCEMENT " +

") " +

"VALUES (UHCL_PR_survey_SEQ.nextval,?,?,?,?,?,?,?,?,?,?,?,?) ";

Object[] parameters = new Object[]{

survey.getUsersPk1(),

survey.getAccreditationPk1(),

survey.getPrivacyTypePk1(),

survey.getFormTypePk1(),

survey.getTitle(),

survey.getDescription(),

new java.sql.Date(survey.getStartDate().toDate().getTime()),

survey.getStartTimeAsUtilString(),

new java.sql.Date(survey.getEndDate().toDate().getTime()),

survey.getEndTimeAsUtilString(),

survey.getGradeCenterColumn(),

survey.getAnnouncement()

};

this.jdbcTemplate.update(sql, parameters);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure! Here's an example of using `jdbcTemplate.batchUpdate()` for inserting data into a database table: ```java public void batchInsert(List<User> users) { String sql = "INSERT INTO users (id, name, age) VALUES (?, ?, ?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement ps, int i) throws SQLException { User user = users.get(i); ps.setInt(1, user.getId()); ps.setString(2, user.getName()); ps.setInt(3, user.getAge()); } @Override public int getBatchSize() { return users.size(); } }); } ``` In this example, we're inserting a list of `User` objects into a table called `users`. The `jdbcTemplate.batchUpdate()` method takes two arguments: the SQL query string and a `BatchPreparedStatementSetter` object that sets the parameter values for each row in the batch. The `setValues()` method in the `BatchPreparedStatementSetter` object sets the parameter values for each row in the batch. In this example, we're getting the `User` object at index `i` in the `users` list and setting its `id`, `name`, and `age` properties as the parameter values for the corresponding placeholders in the SQL query string. The `getBatchSize()` method in the `BatchPreparedStatementSetter` object returns the size of the batch, which is the number of `User` objects in the `users` list. When the `jdbcTemplate.batchUpdate()` method is called, it executes the SQL query string for each row in the batch with the corresponding parameter values set by the `BatchPreparedStatementSetter` object.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值