我收到了这个错误,我已经尝试修复它,但没有。
int nr = nrfromPar; //13
int nrdays = nrfromPar;//1
Date data = datafromPar; //Thu May 11 23:11:09 EEST 2017
String statusRequest = "UPDATE home "
+ "SET date_ma = :data, nr_days_ma = :nrdays "
+ "WHERE nr_req = :nr";
SQLQuery simpleSQL = session.createSQLQuery(statusRequest );
simpleSQL.setParameter("data", data);
simpleSQL.setParameter("nrdays", nrdays);
simpleSQL.setParameter("nr", nr);
int a =simpleSQL.executeUpdate();
System.out.println(a);
结果是:
Hibernate:
UPDATE
home
SET
date_ma = ?,
nr_days_ma = ?
WHERE
nr_req= ?
1
此错误的含义是什么: "由以下原因引起:java.sql.SQLException:没有为参数1" 指定值?
我想使用nativ sql查询,虽然我使用了hibernate注释。
答案 0 :(得分:1)
没有为参数1指定值
您收到此错误,因为您没有为:data, :nrdays, :nr
指定值,它应该是这样的:
SQLQuery simpleSQL = session.createSQLQuery(statusRequest );
simpleSQL.setParameter("data", some_value);
simpleSQL.setParameter("nrdays", some_value);
simpleSQL.setParameter("nr", some_value);
就像你可以像这样使用?
:
String statusRequest = "UPDATE home "
+ "SET date_ma = ?, nr_days_ma = ? "
+ "WHERE nr_req = ?";
SQLQuery simpleSQL = session.createSQLQuery(statusRequest );
simpleSQL.setParameter(1, some_value);
simpleSQL.setParameter(2, some_value);
simpleSQL.setParameter(3, some_value);