热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

HIbernate调用Oracle存储过程

1、创建存储过程Proc代码createorreplaceprocedurechangesalary(p_employeeidnumber,p_newsalarynumber)isbe

1、创建存储过程 Proc代码 create or replace procedure changesalary(p_employeeid number, p_newsalary number) is be

1、创建存储过程

Proc代码

create or replace procedure changesalary(p_employeeid number, p_newsalary number) is begin update employees set salary= p_newsalary where employee_id = p_employeeid; if sql%notfound then raise_application_error(-20100,'Invalid Employee Id'); end if; end; /

2、hibernate配置

Xml代码

org.hibernate.dialect.Oracle9Dialect oracle.jdbc.driver.OracleDriver jdbc:oracle:thin:@localhost:1521:xe hr hr update true

3、hibernate应用

(1)使用JDBC连接

Java代码

import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class CallSP { public static void main(String[] args) throws Exception { Configuration c = new Configuration().configure(); SessionFactory sf = c.buildSessionFactory(); Session session = sf.openSession(); session.beginTransaction(); Connection con = session.connection(); // obtain JDBC connection from Session object CallableStatement cs = con.prepareCall("{ call changesalary(?,?) }"); cs.setInt(1,100); // first parameter index start with 1 cs.setInt(2,6000); // second parameter cs.execute(); // call stored procedure session.getTransaction().commit(); session.close(); sf.close(); } }

(2)使用Native SQL

Java代码


推荐阅读
author-avatar
周周周周芮多
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有