一般我們用pl/sql寫好儲存過程後,用jdbc呼叫的比較多,如何你想用hibernate,那怎麼呼叫儲存過程呢?
下面我們來看看hibernate呼叫oracle的儲存過程 的幾種方式
1.先建立乙個儲存過程如下:
create procedure proc()
begin
select * from user;
end;
create procedure proc1(v_no number(4))
begin
select * from user where empno=v_no;
end;
2.編寫hibernate對映關係
儲存過程對映和領域模型中的實體的對應關係
3hibernate api 對儲存過程的呼叫:
session ss= hibernatesessionfactory.getsession()
list li=ss.getnamedquery("getuser").list();
ss.close();
session ss= hibernatesessionfactory.getsession()
list li=ss.getnamedquery("getuser").list();
ss.close();
4.jdbc api 對儲存過程的呼叫
session session =hibernatesessionfactory.getsession();
connection conn = session.connection();
resultset rs =null;
callablestatement call = conn.preparecall("");
rs = call.executequery();
rs.close();
session.close();
session session =hibernatesessionfactory.getsession();
connection conn = session.connection();
resultset rs =null;
callablestatement call = conn.preparecall("");
rs = call.executequery();
rs.close();
session.close();
5.直接使用 hibernate createquerysql呼叫儲存過程
session session =hibernatesessionfactory.getsession();
sqlquery query = session.createsqlquery("");
list list =query.list();
session.close();
session session =hibernatesessionfactory.getsession();
sqlquery query = session.createsqlquery("");
list list =query.list();
session.close();
6.通過hibernate api或者jdbc,api給儲存過程傳參
callablestatement call = conn.preparecall("");
call.setstring(1, 引數);
rs = call.executequery();
callablestatement call = conn.preparecall("");
call.setstring(1, 引數);
rs = call.executequery();
以上就是儲存過程的幾種使用方式,在實際使用過程中,可能會有些許偏差……
hibernate呼叫儲存過程
drop table if exists user create table user id int 11 not null auto increment,name varchar 16 not null default remark varchar 16 not null default prim...
hibernate呼叫儲存過程
一 建表 drop table if exists user create table user id int 11 not null auto increment,name varchar 16 not null default remark varchar 16 not null default...
hibernate 呼叫儲存過程
create table proctab id int 11 not null auto increment,name varchar 20 age int 11 primary key id 簡單的儲存過程 create procedure proc begin select from proct...