C_____Lee
LeeAtomic
2017-03-26 14:53
采纳率: 75%
浏览 1.9k
已采纳

使用springjdbc提示无效的sql语句

t-sql语句拼接的方式也用了,预处理的方式也用了,但是还是抛出如下异常(在Oracle数据端能查到插入的信息):
在控制台打印的sql语句如下:
insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')

错误信息如下:
HTTP Status 500 - StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

type Exception report

message StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values (2,'个人','张三',88886,sysdate,'私人')]; nested exception is java.sql.SQLException: ORA-00900: 无效 SQL 语句

java 代码如下:
public class IJzxxDaoImpl implements IJzxxDao {
JdbcTemplate temp = new JdbcTemplate(DBUtil.getDs());

@Override
public int insertJzxx(Jzxx jz) {
    Integer dw_id = jz.getDw_id();
    String jz_type = jz.getJz_type();
    String jz_person = jz.getJz_person();
    Integer jz_money = jz.getJz_money();
    String jz_remark = jz.getJz_remark();
    //String sql = "insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values(?,?,?,?,sysdate,?)";
    String sql = "insert into jzxx(dw_id, jz_type, jz_person, jz_money, jz_date, jz_remark) values ("+dw_id+",'"+jz_type+"','"+jz_person+"',"+jz_money+",sysdate,'"+jz_remark+"')";
    System.out.println(sql);
    return temp.queryForInt(sql);
}

各种方法试过了还是搞不定,请大家帮帮忙,谢谢!
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • C_____Lee
    LeeAtomic 2017-03-27 03:18
    已采纳

    是我方法用错了,应该是update()方法而不是queryForInt().

    点赞 评论
  • caozhy

    仔细检查下每个字段的字段名,类型,是否少字段等

    点赞 评论

相关推荐