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) isbegin update employees set salary= p_newsalary where employee_id = p_employeeid;if sql%notfound thenraise_application_error(-20100,’Invalid Employee Id’); end if;end;/
2、hibernate配置
Xml代码
<?xml version=”1.0″ encoding=”UTF-8″?> org.hibernate.dialect.Oracle9Dialectoracle.jdbc.driver.OracleDriverjdbc:oracle:thin:@localhost:1521:xehrhrupdatetrue
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 = se本文来源gao@!dai!ma.com搞$$代^@码5网@ssion.connection(); // obtain JDBC connection from Session objectCallableStatement cs = con.prepareCall(“{ call changesalary(?,?) }”);cs.setInt(1,100); // first parameter index start with 1cs.setInt(2,6000); // second parametercs.execute(); // call stored proceduresession.getTransaction().commit();session.close();sf.close();}}
(2)使用Native SQL
Java代码
,