File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes calling oracle procedures in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "calling oracle procedures in java" Watch "calling oracle procedures in java" New topic

calling oracle procedures in java

subbaraju nadimpalli

Joined: Sep 12, 2006
Posts: 1

i am trying to call oracle procedure in java and it aslo running without errors but i couldn't get the correct results.

i created one procedure in oracle using cursors beacue it retrives more than one record form shows only last record when we call the procedure in java. here the code.

oracle procedure

create or replace procedure Proc_SearchStdInfo_ByName(id out varchar,name in out varchar,add
out varchar,year out varchar ) is
cursor Cursor_SearchByName(name student.sname%type) is select sid,sname,sadd,syear from student where sname=name;
open Cursor_searchByName(name);
fetch Cursor_SearchByName into id,name,add,year;
exit when Cursor_SearchByName%notfound;
---dbms_output.put_line(id||' '||name||' '||add||' '||year);
end loop;
close Cursor_SearchByName;
end Proc_SearchStdInfo_ByName;

i have written code in java like
Student std=new Student();
CallableStatement cs=con.prepareCall("{call Proc_SearchStdInfo_ByName(?,?,?,?)}");
ResultSet rs=cs.executeQuery();

it shows only one record that is the last result of table.

how can we retrive all results from table using oracle procedure
Sujith Kanaparthi
Ranch Hand

Joined: Sep 04, 2005
Posts: 45
Even if you execute the procedure from Oracle you get only the last record values fetched into the out parameters before closing the cursor.I mean if you put "dbms_output.put_line(id||' '||name||' '||add||' '||year);" statement after "end loop;" and before "close Cursor_SearchByName;" statement you will know that.

If you would like to iterate through the cursor from the java code, then you need to have the cursor as out parameter.

Hope this may help you.
I agree. Here's the link:
subject: calling oracle procedures in java
It's not a secret anymore!