java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character to number conversio -
i trying insert record oracle database using procedure. record inserted exception occurs.
public class myproc extends storedprocedure { public thresholdoperationssp(jdbctemplate jdbctemplate, string sql) { super(jdbctemplate, sql); // declare in params declareparameter(new sqlparameter("i_unique_col", types.varchar)); declareparameter(new sqlparameter("i_action", types.varchar)); declareparameter(new sqlparameter("i_table", types.varchar)); declareparameter(new sqlparameter("i_columns", types.varchar)); declareparameter(new sqlparameter("i_values", types.varchar)); declareparameter(new sqlparameter("i_where_col", types.varchar)); declareparameter(new sqlparameter("i_where_values", types.varchar)); declareparameter(new sqlparameter("i_connection", types.varchar)); // declare out params declareparameter(new sqloutparameter("o_unique_id", types.integer)); declareparameter(new sqloutparameter("o_proc_msg", types.varchar)); declareparameter(new sqloutparameter("o_proc_code", types.integer)); declareparameter(new sqloutparameter("o_sql", types.varchar)); compile(); } @suppresswarnings("unchecked") public map<string, object> execute(string connectionname, string tablename, string action, string unqiueidcolumn, string colnames, string newvalues, string wherecolnames, string wherecolvalues) { // process input params & assign map map<string, object> inparams = new hashmap<string, object>(); inparams.put("i_unique_col", unqiueidcolumn); inparams.put("i_action", action); inparams.put("i_table", tablename); inparams.put("i_columns", colnames); inparams.put("i_values", newvalues); inparams.put("i_where_col", wherecolnames); inparams.put("i_where_values", wherecolvalues); inparams.put("i_connection", connectionname); // execute sp map<string, object> resultsummary = execute(inparams); system.out.println(resultsummary); return resultsummary; }
calling above code as:
map<string, object> resultssummary = new myproc(jdbctemplate,"myprocedure").execute("con1","table1","insert","col1","col2","33",null,null);
the above code calls following procedure;
create or replace procedure myprocedure ( i_unique_col in varchar2, i_action in varchar2, i_table in varchar2, i_columns in varchar2, i_values in varchar2, i_where_col in varchar2, i_where_values in varchar2, i_connection in varchar2, o_unique_id out number, o_sql out varchar2, o_proc_msg out varchar2, o_proc_code out number ) p_c_proc_name constant varchar2(50):= 'myprocedure'; p_v_err_cd number; p_v_err_msg varchar2(500); p_v_result varchar2(1); p_v_timestam timestamp time zone; p_v_values varchar2(32767); p_v_sql varchar2(32767); p_v_where varchar2(32767); begin dbms_application_info.set_module (module_name=> p_c_proc_name, action_name=> 'procedure insert-edit actions'); if upper(i_connection) = 'con1' p_v_values := ''''||replace(i_values,',',''',''')||''''; if upper(i_action) = 'insert' case when i_unique_col not null p_v_sql := 'insert uno_comp.'||i_table||' ('||i_columns||' ) values ('||p_v_values||') returning '||i_unique_col||' :1' ; execute immediate p_v_sql using out o_unique_id ; else p_v_sql :='insert uno_comp.'||i_table||' ('||i_columns||' ) values ('||p_v_values||')'; execute immediate p_v_sql; end case; commit; end if; p_v_result := uno_comp.ulog('info', p_c_proc_name, 'successfully performed insert-edit actions '|| p_v_sql, null, null, null ); o_proc_msg := 'procedure edit action complete.'; o_proc_code := 0; end if; end myprocedure;
the error occurs on execution of statement
map<string, object> resultsummary = execute(inparams);
org.springframework.jdbc.badsqlgrammarexception: callablestatementcallback; bad sql grammar [{call myprocedure(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; nested exception java.sql.sqlexception: ora-06502: pl/sql: numeric or value error: character number conversion error\nora-06512: @ line 1\n"
although record inserted database, error occurs after statement executed.
you should use jdbc callablestatements call procedure. how use callable statement
a working example follows ---
import java.sql.*; public class proc { public static void main(string[] args) throws exception { class.forname("oracle.jdbc.driver.oracledriver"); connection con=drivermanager.getconnection( "jdbc:oracle:thin:@localhost:1521:xe","system","oracle"); callablestatement stmt=con.preparecall("{call insertr(?,?)}"); stmt.setint(1,1011); stmt.setstring(2,"amit"); stmt.execute(); system.out.println("success"); } }
the structure of procedure follows ---
create or replace procedure "insertr" (id in number, name in varchar2) begin insert user420 values(id,name); end; /
wiki
Comments
Post a Comment