[Procédure][java] A n'y rien comprendre
Bonjour à tous,
j'ai un petit soucis avec des procédures.
J'execute une procédure et je mets le résultat dans une table temporaire.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| CREATE OR REPLACE
PACKAGE BODY emp_data AS
PROCEDURE open_emp_cv (emp_cv IN OUT EmpCurTyp) IS
cursor cur_emp is select * from emp;
BEGIN
/*
execute immediate 'insert into tmp_emp select * from emp';
*/
for rec_emp in cur_emp loop
execute immediate 'insert into tmp_emp values('||
rec_emp.empno||','''||rec_emp.ename||''','''||rec_emp.job||''','||
rec_emp.mgr||','''||rec_emp.hiredate||''','||rec_emp.sal||','||
rec_emp.comm||','||rec_emp.deptno||')';
end loop;
OPEN emp_cv FOR SELECT * FROM tmp_emp;
END open_emp_cv;
END emp_data;
/ |
lorsque je fais appel à cette procédure via java, elle s'execute et elle me retourne bien un Cursor qui s'affiche dans ma table.
Je change de procédure
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| CREATE OR REPLACE
PACKAGE BODY epss_utils AS
PROCEDURE call_stats_all (cur_all IN OUT StatsCurTyp) IS
--DECLARE
v_reg_total number(20);
v_sub_total number(20);
v_call_code varchar2(50);
v_instrument_code varchar2(30);
v_interimclose date;
v_sub_reg number(20);
v_sub_sub number(20);
v_reg number(20);
v_sub number(20);
v_check boolean;
cursor cur_calls is select * from v_epss_stats order by call_code, instrument_code, interimclose;
BEGIN
v_check := true;
for rec_call in cur_calls loop
if rec_call.call_code = v_call_code then
if rec_call.instrument_code= v_instrument_code then
v_check := false;
else
v_check := true;
end if;
else
v_check := true;
end if;
v_call_code := rec_call.call_code;
v_instrument_code := rec_call.instrument_code;
/* when no interimclosing date has been found return the final closing date */
if rec_call.INTERIMCLOSE is null then
v_interimclose := rec_call.FINALCLOSE;
else
v_interimclose := rec_call.INTERIMCLOSE;
end if;
execute immediate 'select registrations, submitted from v_epss_stats_totals where call_code='''||v_call_code||''' and instrument_code ='''||v_instrument_code||'''' into v_reg_total, v_sub_total;
v_reg := rec_call.registrations;
v_sub := rec_call.submitted;
if v_check = false then
v_reg := rec_call.registrations - v_sub_reg;
v_sub := rec_call.submitted - v_sub_sub;
v_sub_reg := v_sub_reg + v_reg;
v_sub_sub := v_sub_sub + v_sub;
else
v_sub_reg := v_reg;
v_sub_sub := v_sub;
end if;
dbms_output.put_line('insert into TMP_EPSS_STATS values('''||v_call_code||
''','''||v_instrument_code||''','''||rec_call.open||''','''||
rec_call.FINALCLOSE||''','''||rec_call.INTERIMCLOSE||''','||v_reg_total||','||v_reg||','||v_sub_total||','||v_sub||')');
execute immediate 'insert into TMP_EPSS_STATS values('''||v_call_code||
''','''||v_instrument_code||''','''||rec_call.open||''','''||
rec_call.FINALCLOSE||''','''||rec_call.INTERIMCLOSE||''','||v_reg_total||','||v_reg||','||v_sub_total||','||v_sub||')';
end loop;
OPEN cur_all FOR SELECT * FROM TMP_EPSS_STATS;
END call_stats_all;
END epss_utils;
/ |
elle s'execute mais ne retourne rien du tout via Java.
Pourtant ces 2 procédures fonctionnent, je les ai essayées avec SQL Navigator et me retournent chacune un cursor.
voici le bout de code utilisé pour appeler ces procédures.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| //stmt = conn.prepareCall("{ call emp_data.open_emp_cv(?) }");
stmt = conn.prepareCall("{ call epss_utils.call_stats_all(?) }");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.execute();
cursor = ((OracleCallableStatement)stmt).getCursor(1);
// get the meta data
ResultSetMetaData meta = cursor.getMetaData();
// get the number of COLUMNS from the metadata
colnum = meta.getColumnCount();
// Put the column names in the Vector
for(i=1;i<= colnum ;i++){
columnNames.add(meta.getColumnName(i));
}
//set size of the Table
resultSet.setModel(new DefaultTableModel(columnNames,Rownum));
// Statement s = conn.createStatement();
// Filling up the table
r = 0;
while( cursor.next()){
//System.out.println(r + " " + rs.getString(1) + " " +rs.getString(2));
for(i=1;i<=colnum;i++){
//System.out.println("i=" + i);
resultSet.setValueAt(cursor.getString(i),r,i-1);
}
r++;
}
}
}
catch(SQLException sqle)
{
sqle.printStackTrace();
} |
Je redoute un bug au niveau de java.
Si quelqu'un a une idée elle est la bienvenue.
D'avance merci pour vos réponses.