this code gives “Incorrectly set or registered parameter” SQLException. Can anyone help please?
OracleConnection conn = getAppConnection();
String q = "BEGIN INSERT INTO tb (id) values (claim_seq.nextval) returning id into :newId; end;" ;
CallableStatement cs = (OracleCallableStatement) conn.prepareCall(q);
cs.registerOutParameter("newId", OracleTypes.NUMBER);
cs.execute();
int newId = cs.getInt("newId");
JDBC does not support named binding, so it stops here.
Either live with indexed placeholders
?or add an extra abstraction layer on top of JDBC which supports named parameters, e.g. Hibernate and/or JPA.See also: