Sunday, October 25, 2009
Experimenting with Oracle DBMS_LOCK
First, grant privilege to play with it. For example,
How to try it out in SQL Developer ?Login as user SYS with SYSDBA role, then
grant all on dbms_lock to public;
How to do it in JDBC ?set serveroutput on;
declare
v_result integer;
begin
v_result := DBMS_LOCK.REQUEST(123, 6, 0, true);
dbms_output.put_line(
case
when v_result=0 then 'Success'
when v_result=1 then 'Timeout'
when v_result=2 then 'Deadlock'
when v_result=3 then 'Parameter Error'
when v_result=4 then 'Already owned'
when v_result=5 then 'Illegal Lock Handle'
end);
end;
Connection conn = ...
CallableStatement stmt = conn.prepareCall("{call ? := DBMS_LOCK.REQUEST(?, 6, 0, true)}");
stmt.registerOutParameter(1, Types.INTEGER);
stmt.setBigDecimal(2, new BigDecimal(123));
stmt.execute();
int result = stmt.getInt(1);
System.out.println("result: " + result);
Comments:
<< Home
I have also so many things with this option and have faced so many interesting results. The one that you have shared are new and appealing one. I will surely try them now and see what output I will get.
Post a Comment
<< Home