Lock records

Hey all,
I read most of the posts regarding this issue and I still can't find a solution to my problem, actually I don't really know what is my problem so here I am. This is the codes that I use to attempt to lock all the retrieved records
conn.setAutoCommit(false);
PreparedStatement pstmt = null;
ResultSet rs = null;
String query = "SELECT * FROM MYTABLE FOR UPDATE";
try {       
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
} catch (Exception e) { }
then I test it by running 2 instances of this....however, it seems to me no matter what....both can modifies the table freely. Does anyone know what I am doing wrong? Thanks!

Also, WorkForFood would please give some a fragment
of codes that show how to declare a cursor FOR
UPDATE? PLEASE!I guess the point of my last post is that when you declare a cursor for update (which you do using SQL) it does NOT do what exactly what you want. You don't want to hint at locking the rows; you said you want to actually lock the rows. Here is the general syntax, check the DB2 reference manual for specifics:
"SELECT <columns-list> FROM <tablename> WHERE <where-expression> FOR UPDATE". OK, let's talk about what you are doing; which I think may be more the issue then how to do it. Why do you believe you should lock the rows? The DB2 authors have probably spent billions of dollars developing sophisticated lock managers that gracefully handle almost any situation that can arise when multiple users are accessing the same data concurrently. This begs the question, why are you special, and why do you think you can write it better then they did? Perhaps you already know the transactional flow within Java, but here is a bit of pseudo-code that may help out if you don�t.
CONNECT TO DATABASE
TURN AUTO-COMMIT OFF
START PROCESSING
DO WHILE ANOTHER TRANSACTION
   <TRANSACTION>
      SELECT FOR UPDATE (IF YOU WANT)
      PROCESS TO YOUR HEARTS CONTENT INCLUDING ADDITIONAL SELECT, INSERT, UPDATE, DELETE
      COMMIT ALL CHANGES
   </TRANSACTION>
END DO
END PROCESSING
DISCONNECT FROM DATABASE
Note: <TRANSACTION> is a logical step that occurs when you turn of auto-commit processing. There is nothing to code;, no syntax that actually starts the transaction. A transaction is what occurs between issuing of commits.
1) No one will see any of the changes you make to these rows until you issue the commit (that is the transactional processing). So if you are worried about people viewing partially changed content, it is a non-issue.
2) If someone were to issue an update against the same data you are updating, and you updated it first, their updates will wait and/or fail (and vice versa). There are standard Exception coding practices for handling that situation, but in a cooperative environment it comes up much less then you would think thanks to the DB2 gurus that wrote the lock manager.
3) Locking on large amounts of data in a batch or online program is a bad coding practice. If this is an online program, how long will you hold the lock while the user leaves a screen up and goes to lunch? Batch programs can deal with millions of rows. Locking on 100's or 1000's of rows that you �might� update can bring an application to a halt so again; avoid doing that through use of transactional processing.
I guess it's my contention that unless you have an extraordinary need, explicit locking of a table or rows within a table is not necessary. This en mass locking can and should be avoided through transactional processing which allows the DB2 lock manager to hide the complexity of concurrent usage.
If you are trying to fix a concurrency problem that is occurring in a production program, there may be another way to fix it. If this is a new program, focus on using transactions and I don�t think you will have to worry too much about the actual locking within the database.
This is just my two cents, and while there may not be anything new described here, I thought I would be remiss if I didn�t question a little on what you were doing rather then focus on how to do it. The issues and problems inherent in locking that you seem concerned about are not Java specific and you may want to consider asking similar questions in a DB2 forum.
WFF

Similar Messages

  • Lock records when in Update Mode / problem with 2 users on 1 document

    Hi,
    when user A updates e.g. a purchase order and user B goes into this purchase order and updates e.g. the remark before user A, then user A cannot save his changes. Imagine user A has put in several new lines and has made several price adjustments, his work will be gone.
    In most cases this should not happen very often, but it could. Since B1 recognizes when another user has updated the document before, it should be possible to solve this situation more convenient (either by lock, saving to a new document, comparing to the old version, etc).
    Thank you
    Sebastian

    Hi Sebastian,
    Your request is understandable. It may not have big problem to change current process by coding. However to lock records whenever in update mode, that could create too many locks. It is basically not good for performance. The trade off may be allowing save as function. However, this may not be a desirable solution for most end users.
    Thanks,
    Gordon

  • How to lock record in a remote database ???

    Hi All!
    How to lock record in a remote table ??? Is it possible to lock by using the RPC ??? What are the options available ??
    thanks
    Sanjeeb Bose
    HCL Infosystems Ltd
    Kolkata India

    DBLinks may be one option...
    --Shirish                                                                                                                                                                                                                       

  • Reading Locked records from HR table using LDB PNP

    Hi,
    I am trying to read the table pa0168 using LDB PNP.
    But the problem is that get pernr staement does not retrieve locked records i.e where PA0168-sprps eq "X'.
    Can anybody help me with this.
    I have to use LDB  so i don't want a solution of writing a select * for the pa0168 table.
    hence i have to use get pernr statement but it should also retrieve locked records.
    how can i achieve that.? please help
    Thanks
    GT
    Message was edited by: GT

    Hi GT,
    In the START-OF-SELECTION event, set the parameter value
    pnp-sw-ignorelockedrecords = 'N'.
    Good Luck,
    Suresh Datti
    ( Pl award points if the answer helps you )

  • Standard Report to display locked records of an infotype

    Hi All,
    Is there any SAP standard report to display the locked records of an employee.
    Suppose for an employee his two absence record has been locked and one additional payment has been locked. Is there any SAP standard report to display his locked records.
    Thanks and Regards,
    Visali. Malepati

    Hi,
    Hi there is no standard report  to get the locked records.
    You create a query thru quick viewer.
    where you can heve selection field as lock indicator and Personnel number.
    Steps:
    1. Goto SQ01
    click Qucikviewer
    or
    SQVI
    2.Create a new query
    Datasouce:Table
    Table:PA0006
    3.Lst field Selection tab:
    Add the fields pernr,lock indicator,enddat,begdate.
    4.Selection fields Tab:
    Add the fields pernr,lock indicator
    5.Execute:
    Your Query is ready now:

  • How to lock records in 8.1.7?

    Hi,
    How can I lock records in 8.1.7 so that only one user can select/update these records at one time? If possible, can it return an error mesg if one user try to select/update records locked by others?
    Thanks a lot.
    David

    Oracle automatically locks a row just before updating or deleting.
    You can lock rows explicitly before doing an update etc by selecting it for update:
    select * from emp where empno=21 for update;
    update emp
    set sal=sal*1.1
    where empno=21;
    commit;
    The lock will be released on the commit (or rollback).
    Please note that in Oracle, writers never block readers and readers never block writers. Which means, that although you have locked a row (or group of rows) for update, other users will still be able to select against those rows (in the pre-changed or consistant state).

  • How to get locked records of a pernr while using PNP LDB

    is there any way to retrieve locked records of a pernr
    while using PNP LDB??currently the get pernr event is unable to load locked records of a pernr.

    Hi,
    PL use this piece of code in your Program..
    INITIALIZATION.
    PNP-SW-IGNORELOCKEDRECORDS = 'N'.
    Regards,
    Suresh Datti

  • Custom Infotype not displaying locked records in the list screen (3000)

    I have a custom infotype (9xxx) that will not display the locked records (locked indicator (sprps) is set to X) in the list screen (3000) in PA20 and PA30.
    Any ideas on what may be causing the records to not display in the list screen?
    Thanks,
    Ted

    Hi,
    for creating both employee and appliciant infotype you must check 'Both'  in PM01  IT tab.
    Regards.

  • Lock records command

    Hi all,
    I have a scenario where i have to lock the lookup table records for editing. So that other users cannot edit the record.
    I am processing the lock record command for records which are not locked by other session (LOCK_BY_OTHER_SESSION).
    Lets say User A lock the records.
    I am loging in to the data manager using User B. When i try to edit and save the locked records data manager should warn me with a message like "Record has been locked by other user. would you like to edit anyway?". But i am not getting any warning message.
    I doubt the records were not locked by user A.
    Is my understanding correct? Am i missing any step here? Please help!
    Best regards,
    Arun prabhu S

    Found the answer!
    Lock will be lost once the user session destroyed.

  • Locked Records Indicator

    Hi,
    Here is the scenario:
    We have several users (in AutoCAD) that retrieve, delete, modify, and post data back to Oracle Spatial DB (10g).
    During data retrieval, we use the SDO_WITHIN_DISTANCE operator based from either a Road Name or Building Name with a flexible buffer distance. Now, the chances of the users having retrieved the same records are very high.
    My query is, is there an indicator in the row level that will show that the particular record has already been locked/retrieved by another user? I have read about the "SELECT .... FOR UPDATE" system of locking records, but the problem would be the possibilities of having a "Lockout" or a "Deadlock". That is why, we would like to handle the records firsthand before displaying it into AutoCAD.
    Knowing this, we can provide some mechanism in AutoCAD to avoid the record to be modified or deleted by another user (i.e. giving a read-only attribute, changing layer or color, etc. etc.).
    Thank you very much for your ideas.
    Regards,
    Arnold Higuit

    Depending on your requirements, you may want to do the initial query without trying to lock the records (if you do the select ... for update nowait on the initial query and there are records locked, it will fail).
    After you do your initial query, then you can try to select individual records by a unique key for update (using nowait), and any record that is already locked can be styled in an appropriate way.
    Note this will be significantly slower (selecting each individual record).

  • Lock record problem.

    Hi All. I use Firebird DB with WLS. In Firebird when no DataBase transaction parameters specified the default parameters is set. By default transaction isolation levels is "concurency, wait". It means that when 2 concurrent transations try to lock record (select ... from table for update), second transactoin waits while the first will be complete. I need exception in this case (nowait in transactoin parameters).
    In Firebird JDBC driver there is a file with mapping to standart jdbc transaction isolation levels:
    TRANSACTION_SERIALIZABLE=isc_tpb_consistency,isc_tpb_write,isc_tpb_wait
    TRANSACTION_REPEATABLE_READ=isc_tpb_concurrency,isc_tpb_write,isc_tpb_wait
    TRANSACTION_READ_COMMITTED=isc_tpb_read_committed,isc_tpb_rec_version,isc_tpb_write,isc_tpb_wait
    I change wait to nowait in this file, bat i dont no where i can set transaction isolation level on weblogic server. How I can do this?

    In the on-lock trigger, instead of Lock_record; you should write your own sql "select for update no wait".
    Then I am not sure... either write your own exception clause to trap the ORA-00054, or trap the exception in the on-error trigger.

  • Lock records (urgent)

    Dear members,
    I hava a problem with lock record. Would you please help me to solve my problem. I had read on OTN messages about locking records that others members have used the following:
    On_lock trigger(Block level)
    Lock_record;
    On_Error trigger(Form level)
    DECLARE
    errnum NUMBER := ERROR_CODE;
    errtxt VARCHAR2(80) := ERROR_TEXT;
    errtyp VARCHAR2(3) := ERROR_TYPE;
    BEGIN
    IF errnum = 40501 THEN
         message('This record has been locked by another user');               
    ELSE
         Message(errtyp||'-'||TO_CHAR(errnum)||': '||errtxt);
    END IF;          
    RAISE Form_Trigger_Failure;
    END;
    I still received the ORACLE message "COULD NOT RESERVE RECORD(2 TRIES). KEEP TRYING? YES OR NO".
    If I select "NO" my message will come up, but I want the ORACLE message suppressed. How do I do that!
    THANKS

    In the on-lock trigger, instead of Lock_record; you should write your own sql "select for update no wait".
    Then I am not sure... either write your own exception clause to trap the ORA-00054, or trap the exception in the on-error trigger.

  • Locked record in infotype 0167

    Hi,
    I would be thankful if some one can explain me the concept of lock record of an employee in infotype 0167.
    As in one of my requirement i have to fetch both the records ie active and locked (having same begda and endda).
    Is there any specific thing i need to do apart from
    INITIALIZATION.
    pnp-sw-ignorelockedrecords = 'N'.
    Regards
    Manu

    Hi Manu,
    Locked record means taht record id not yet ready to process / use in reporting, becuase that data is insuffient. You can lock/unlock a infotype record using pA30-0167-edit-Lock/Unlock option.
    For example infotype 2001 or 2002.
    Regards,
    Ranjith

  • Release lock record

    hi everybody,
    i want to know how can i release lock record? is there any setting in application server to do this?
    thanks a lot

    Hi
    Please give some more information as your question does not seem to be complete.
    Are you talking about Operating system lock or database lock .
    Please provide the correct release you are currently using .
    Regards
    Sadiq

  • Locking records entered through ESS

    Is it possible to make it so that when an employee enters data through Personal Data, they enter locked records instead of actually writing directly to the database?
    We're researching the ability to have the employees enter locked records and then having an HR Administrator unlock them after reviewing them
    Anyone done this before?

    Tim,
    You can be selective about which Infotypes are locked by default via authorisations, as there is a seperate auth check for each Infotype available.  Where it doesn't work well is in cases where you only want the Infotype locked in some circumstances.
    Probably the ultimate solution would be something built with the new HCM Processes & Forms, and the new HR Administrator functionality on the portal side.
    I think there is already a standard example delivered for the US recently, where the usual ESS address Webdynpro has been replaced by a form that gets actioned by the HR Admins before the Infotype gets updated.
    Chris can possibly give you some more info on that, I hear he just luuuuuves that stuff
    Regards,
    John

  • How to know the SID of the particular locked record?

    Hi, this is generic question.
    please tell me the solution for the below requirment.
    One user has locked a record in table ‘EMP’ for UPDATE – transaction/row level lock.. The Emp_ID = 123 is locked.
    2nd user also tries to update the same record(emp_id=123) in the table but will not be able to lock it bcoz 1st user has locked it….
    Requirement is the 2nd user should get a message indicating who has locked that particular record(emp_id=123)..
    V$lock, dba_locks, v$transaction etc., will give all the SIDs that have locks on the table (bcoz many users will be having row level locks on different records on the same table)
    but I want only the SID which has locked desired record (emp_ID=123)
    Can you give any solution ?

    Hema wrote:
    Can you give any solution ?
    How about addressing and fixing the business process where two different users at the same time need to change the exact same business entity?
    Showing the locked session/user does not fix the problem.  It is a technical workaround. Technical "solutions" like these does not and cannot address inherent business process conflicts.

Maybe you are looking for

  • Can Windows 7 be installed using the latest version of boot camp on 3TB fusion iMac drive?

    I have tried unsuccessfully several times to install an .ISO version of 64-bit Windows 7 SP1 on my late 2012 iMac, equipped with a 3TB fusion drive. My proposed Windows partition, set up under boot camp assistant from the utility folder, is well unde

  • Smart Web Printing problems

    When I try to run HP Smart Web Printing feature I can go out a get segments to print with no problem.  But, when I go to print or edit it, this Runtime Error message appears in a dialog box that is titled Microsoft Visual C++ Runtime Library.  Has an

  • Hard Drive will not Mount

    I have a Seagate Barracuda 1.5 Gig installed in a MacPro as an additional drive and as of today the drive will not mount.  Yersterday I noticed it ejected itself; I immediately rebooted and started to download the data to another drive but it ejected

  • Trying to do a knockout with text.

    I admittedly am an amature illustrator user. I have only used it for a week now. I do have experience in photoshop so the learning curve was ok. I want to create a vector logo so I cannot use photoshop. I know how to do what I want to do in photoshop

  • Default printer changes to Send to One Note printer

    I have Office 2013 and Windows 8.1. The problem is, that even if I change the default printer to my laser printer, it changes to Sned to One note printer. Should I disable the send to one note printer or how can I keep my default printer unchanged?