开发者社区> 问答> 正文

insert语句在pl/sql中替换数据可以执行,但是java中却报错

java code:

public int initiating(String title, String content, String numberLimit,String fkCustomerId) {
String pkId = "44";
String sql="insert into ACTIVITY_INFO (pk_id,title,content,fk_customer_id,number_limit,create_date) values(:pkId,:title,:content,:fkCustomerId,:numberLimit,sysdate)";
Query query = this.getSession().createQuery(sql);
query.setParameter("pkId", pkId);
query.setParameter("title", title);
query.setParameter("content", content);
query.setParameter("fkCustomerId", fkCustomerId);
query.setParameter("numberLimit", numberLimit);
int num = query.executeUpdate();
return num;
}

报错信息:

严重: Servlet.service() for servlet [springMvc] in context with path [/CREOAMS] threw exception [Request processing failed; nested exception is org.hibernate.hql.ast.QuerySyntaxException: unexpected token: values near line 1, column 89 [insert into ACTIVITY_INFO (pk_id,title,content,fk_customer_id,number_limit,create_date) values(:pkId,:title,:content,:fkCustomerId,:numberLimit,sysdate)]] with root cause
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: values near line 1, column 89 [insert into ACTIVITY_INFO (pk_id,title,content,fk_customer_id,number_limit,create_date) values(:pkId,:title,:content,:fkCustomerId,:numberLimit,sysdate)]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)

展开
收起
蛮大人123 2016-03-17 14:54:40 3138 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    Query query = this.getSession().createQuery(sql);//HQL语句不能这么写,直接用save就完了。
    使用
    Query query = this.getSession().createSQLQuery(sql);

    2019-07-17 19:05:24
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java单元测试实战 立即下载
Java应用提速(速度与激情) 立即下载
Java工程师必读手册 立即下载