java - not able to insert values in my postgresql database -
in java code:
callablestatement cs=null; int bcode=1; int dcode=3; int noftab=3; string sql2 = "{? = call public.insertdepttables('"+bcode+"','"+dcode+"','"+noftab+"')}"; cs = conn.preparecall(sql2); cs.registeroutparameter(1,types.integer); rset1=cs.getint(1); system.out.println("success="+rest1);
in insertdepttables:(function in db-postgresql)
create or replace function public.insertdepttables ( in branch_code integer, in dept_code integer, in no_tables integer ) returns integer $$ declare count integer; begin if no_tables>0 loop insert t_dept_tables(branch_code,dept_code,table_no)values(branch_code,dept_code,no_tables); no_tables=no_tables-1; count=count+1; exit when no_tables =0; end loop ; end if; return count; end $$
actually need insert no_table (i.e.,3) times row in t_dept_tables in postgresql. wat have done hav written functions in database. need call java code. used callable stmt there:
my output should in db:
bcode dcode table_no 1 3 1 1 3 2 1 3 3
now while executing java code, i'm getting result as,
console:
success=3
but 3 rows arent inserted in db, while executing function in db, values inserted. no wrong in db function. please me sort out.
are sure haven't forgot call statement, like:
cs.executequery(); ... cs.close();
btw, task achieved without functions, (don't use string concatenation, use parameter values):
string stm = "insert t_dept_tables(branch_code,dept_code,table_no) values(branch_code,dept_code,no_tables); values(?, ?, ?)"; cs = con.preparestatement(stm); cs.setint(1, id); cs.setint(3, id); cs.setint(3, id); rs = cs.executeupdate();
Comments
Post a Comment