java - CallableStatement + procedure to insert new row selected from the same table return new PK -
i trying insert new row in table re-create of row selected same table. have created procedure selects row based on id table , inserts same table new values. procedure returns pk of new row.
when execute callablestatement, below exception:
java.sql.sqlexception: ora-06550: line 1, column 371: pl/sql: ora-00933: sql command not ended ora-06550: line 1, column 7: pl/sql: sql statement ignored @ oracle.jdbc.driver.sqlstatemapping.newsqlexception(sqlstatemapping.java:70)
i not able find error
commond not ended
in procedure
my code reference. help or hint appreciated. give thanks you.
public void updatefiletothisversion(vamediafile filedto, long frommediaid){ connection conn = null; callablestatement cst = null; seek { string insertquery = "begin insert va_media_file (vmf_id, vmf_file_name, vmf_file, vmf_file_content_type, vmf_file_ver_num, vmf_is_active, vmf_uploaded_by_role_id, vmf_uploaded_by_user_id, vmf_uploaded_ts, vmf_comments) " + " (select vmf_id_seq_num.nextval, vmf_file_name, vmf_file, vmf_file_content_type, ?, 'y', ?, ?, sysdate, vmf_comments va_media_file vmf_id = ?) returning vmf_id ?; end;"; conn = getconnection(); conn.setautocommit(false); cst = conn.preparecall(insertquery); cst.setstring(1, filedto.getfilevernum()); cst.setstring(2, filedto.getuploadedbyroleid()); cst.setstring(3, filedto.getuploadedbyuserid()); cst.setlong(4, frommediaid); cst.registeroutparameter(5, types.numeric); cst.execute(); long newrecordid = cst.getlong(5); if(newrecordid != 0l){ conn.commit(); } } grab (exception sqlexception) { } { oracledaoutils.closequietly(cst, conn); } }
oracle doesn't seem mixing "select statement within insert statement" "returning" clause. first, need separate select statement selects record type contains fields in select statement. can assign vmf_id record jdbc output parameter. can utilize record in insert statement.
java oracle stored-procedures callable-statement
No comments:
Post a Comment