Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to anticipate (Oracle) database locks.

Re: How to anticipate (Oracle) database locks.

From: Tony Tay <tonytay_at_tpg.com.au>
Date: Tue, 20 May 2003 17:17:03 +1000
Message-ID: <3ec9d674@dnews.tpgi.com.au>


hi,

I suggest you do something like that:

    Select for update nowait
    update and commit if successful
    release lock otherwise

What the select for update Sql command does is that it will stop anyone from editing the row.

There may be otherways of doing it. I use that for my system which has many users and it works fine.

"Jan Brunia" <j.j.brunia_at_speed.a2000.nl> wrote in message news:HMRxa.409499$qm4.42554595_at_amsnews03.chello.com...
> Hi,
>
> We have the problem of encountering database locks in our
> Java program. De piece of code most probably causing
> the lock is shown below.
>
> Has anybody some advise concerning how to avoid the locks
> and when they happen how to handle them and remove them
> runtime?
>
> Many thanks,
>
> Jan
>
> ---------------------------------------------------------------------
> public void deleteByCustomerId(CustomerNr customerId)
> throws MvpnException {
> Database database = new Database(Bootstrap.getConfig(),
"billing");
>
> try {
> database.setAutoCommit(false);
>
> PreparedStatement preparedStatement =
> database.prepareStatement(SQL_DELETE_VIRTUAL_MEMBERS);
> preparedStatement.setString(1, customerId.toBilling());
> preparedStatement.execute();
>
> preparedStatement =
> database.prepareStatement(SQL_DELETE_SUBSCRIBERS);
> preparedStatement.setString(1, customerId.toBilling());
> preparedStatement.execute();
>
> preparedStatement =
> database.prepareStatement(SQL_DELETE_CUSTOMER);
> preparedStatement.setString(1, customerId.toBilling());
> preparedStatement.execute();
>
> database.commit();
> } catch(SQLException e) {
> try {
> database.rollback();
> } catch(SQLException e1) {
> } finally {
> log.error("sql error while storing parse result: ", e);
> throw new MvpnException(e);
> }
> } finally {
> database.close();
> }
> }
>
> --------------------------------------------------------------------------

--

>
>
>
>
>
Received on Tue May 20 2003 - 02:17:03 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US