tags:

views:

25

answers:

1

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");
+1  A: 

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:

BalusC