hi
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 table.it 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;
begin
open Cursor_searchByName(name);
loop
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(?,?,?,?)}");
cs.registerOutParameter(1,Types.VARCHAR);
cs.registerOutParameter(2,Types.VARCHAR);
cs.registerOutParameter(3,Types.VARCHAR);
cs.registerOutParameter(4,Types.VARCHAR);
cs.setString(2,sname);
ResultSet rs=cs.executeQuery();
if(rs!=null)
{
while(rs.next())
{
std.setID(cs.getString(1));
std.setName(cs.getString(2));
std.setAdd(cs.getString(3));
std.setYear(cs.getString(4));
}
}
it shows only one record that is the last result of table.
how can we retrive all results from table using oracle procedure